Skip to content

Commit d261334

Browse files
committed
extract debounce delay constant and improve lintFile documentation
- Extract LINT_FILE_DEBOUNCE_DELAY constant for debounce delay value - Create lintFileDebounced function with proper documentation - Simplify lintFile documentation comment - Fix optional chaining for linterTree.isIgnored call
1 parent f742772 commit d261334

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

server/src/server.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import { loadAglintModule, type LoadedAglint } from './utils/aglint-loader';
4949
import { getErrorMessage, getErrorStack } from './utils/error';
5050
import { isFileUri } from './utils/uri';
5151

52+
const LINT_FILE_DEBOUNCE_DELAY = 100;
53+
5254
/**
5355
* Create a connection for the server, using Node's IPC as a transport.
5456
* Also include all preview / proposed LSP features.
@@ -269,9 +271,7 @@ const getVscodeDiagnosticsFromLinterResult = (linterResult: LinterResult): Diagn
269271
};
270272

271273
/**
272-
* Lint the document and send the diagnostics to VSCode. It handles the
273-
* ignore & config files, since it uses the cached scan result, which
274-
* is based on the AGLint CLI logic.
274+
* Lint the document and send the diagnostics to VSCode.
275275
*
276276
* @param textDocument Document to lint.
277277
*/
@@ -281,7 +281,8 @@ async function lintFile(textDocument: TextDocument): Promise<void> {
281281
|| !workspaceRoot
282282
|| !settings.enableAglint
283283
|| !aglint
284-
|| await linterTree?.isIgnored(fileURLToPath(textDocument.uri))
284+
|| !linterTree
285+
|| await linterTree.isIgnored(fileURLToPath(textDocument.uri))
285286
) {
286287
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
287288
return;
@@ -335,6 +336,14 @@ async function lintFile(textDocument: TextDocument): Promise<void> {
335336
}
336337
}
337338

339+
/**
340+
* Lint the document and send the diagnostics to VSCode.
341+
* Debounced version of {@link lintFile}.
342+
*
343+
* @param textDocument Document to lint.
344+
*/
345+
const lintFileDebounced = debounce(lintFile, LINT_FILE_DEBOUNCE_DELAY);
346+
338347
/**
339348
* Parse AGLint config comment rule in a tolerant way (did not throw on parsing error).
340349
*
@@ -776,7 +785,7 @@ connection.onDidChangeWatchedFiles(async () => {
776785
// The content of a text document has changed. This event is emitted
777786
// when the text document first opened or when its content has changed.
778787
documents.onDidChangeContent((change) => {
779-
debounce(lintFile, 100)(change.document);
788+
lintFileDebounced(change.document);
780789
});
781790

782791
connection.onInitialized(async () => {

0 commit comments

Comments
 (0)