Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add run option for postponing validation until the document is saved #449

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ Controls the package manager to be used to resolve the Stylelint library. This s

An array of language identifiers specifying which files to enable snippets for.

### `stylelint.run`

> Type: `"onType" | "onSave"`
> Default: `"onType"`

Controls when Stylelint is run. Valid values are `"onType"` or `"onSave"`. When set to `"onType"`, styles are validated on every keystroke. When set to `"onSave"`, validation is postponed until the document is saved.

### `editor.codeActionsOnSave`

This extension provides an action that you can use with VS Code's [`editor.codeActionsOnSave`][vscode settings] setting. If provided a `source.fixAll.stylelint` property set to `true`, all auto-fixable Stylelint errors will be fixed on save.
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
"additionalProperties": false,
"description": "Options for the disable lint rule action in the quick fix menu."
},
"stylelint.run": {
"scope": "resource",
"type": "string",
"enum": [
"onType",
"onSave"
],
"default": "onType",
"description": "Control when Stylelint valiation is performed."
},
"stylelint.config": {
"scope": "resource",
"type": [
Expand Down
20 changes: 17 additions & 3 deletions src/server/modules/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,26 @@ export class ValidatorModule implements LanguageServerModule {

this.#logger?.debug('onDidChangeWatchedFiles handler registered');

this.#context.documents.onDidChangeContent(
async ({ document }) => await this.#validate(document),
);
this.#context.documents.onDidChangeContent(async ({ document }) => {
const options = await this.#context.getOptions(document.uri);

if (options.run !== 'onSave') {
await this.#validate(document);
}
});

this.#logger?.debug('onDidChangeContent handler registered');

this.#context.documents.onDidSave(async ({ document }) => {
const options = await this.#context.getOptions(document.uri);

if (options.run === 'onSave') {
await this.#validate(document);
}
});

this.#logger?.debug('onDidSave handler registered');

this.#context.documents.onDidClose(({ document }) => {
this.#clearDiagnostics(document);
});
Expand Down
1 change: 1 addition & 0 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export type LanguageServerOptions = {
location: 'separateLine' | 'sameLine';
};
};
run?: 'onType' | 'onSave';
config?: stylelint.Config | null;
configBasedir?: string;
configFile?: string;
Expand Down