From 33b36dcbf20d032664539bba0864f260c619831c Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 20 Mar 2023 13:50:08 -0400 Subject: [PATCH] Lint the language server package --- languageserver/src/connection.ts | 27 +++++++++++++------------ languageserver/src/context-providers.ts | 2 +- languageserver/src/value-providers.ts | 6 +++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/languageserver/src/connection.ts b/languageserver/src/connection.ts index 6188335..777f9bd 100644 --- a/languageserver/src/connection.ts +++ b/languageserver/src/connection.ts @@ -12,6 +12,7 @@ import { HoverParams, InitializeParams, InitializeResult, + TextDocumentIdentifier, TextDocumentPositionParams, TextDocuments, TextDocumentSyncKind @@ -38,7 +39,6 @@ export function initConnection(connection: Connection) { const cache = new TTLCache(); let hasWorkspaceFolderCapability = false; - let hasDiagnosticRelatedInformationCapability = false; // Register remote console logger with language service registerLogger(connection.console); @@ -47,13 +47,8 @@ export function initConnection(connection: Connection) { const capabilities = params.capabilities; hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders); - hasDiagnosticRelatedInformationCapability = !!( - capabilities.textDocument && - capabilities.textDocument.publishDiagnostics && - capabilities.textDocument.publishDiagnostics.relatedInformation - ); - const options: InitializationOptions = params.initializationOptions; + const options = params.initializationOptions as InitializationOptions; if (options.sessionToken) { client = getClient(options.sessionToken, options.userAgent); @@ -94,7 +89,7 @@ export function initConnection(connection: Connection) { connection.onInitialized(() => { if (hasWorkspaceFolderCapability) { - connection.workspace.onDidChangeWorkspaceFolders(_event => { + connection.workspace.onDidChangeWorkspaceFolders(() => { clearCache(); }); } @@ -136,7 +131,7 @@ export function initConnection(connection: Connection) { await onCompletion( connection, position, - documents.get(textDocument.uri)!, + getDocument(documents, textDocument), client, repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)), cache @@ -147,7 +142,7 @@ export function initConnection(connection: Connection) { connection.onHover(async ({position, textDocument}: HoverParams): Promise => { return timeOperation("hover", async () => { const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)); - return await hover(documents.get(textDocument.uri)!, position, { + return await hover(getDocument(documents, textDocument), position, { descriptionProvider: descriptionProvider(client, cache), contextProviderConfig: repoContext && contextProviders(client, repoContext, cache), fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => { @@ -157,16 +152,16 @@ export function initConnection(connection: Connection) { }); }); - connection.onRequest("workspace/executeCommand", (params: ExecuteCommandParams) => { + connection.onRequest("workspace/executeCommand", async (params: ExecuteCommandParams) => { if (params.command === Commands.ClearCache) { cache.clear(); - documents.all().forEach(validateTextDocument); + await Promise.all(documents.all().map(doc => validateTextDocument(doc))); } }); connection.onDocumentLinks(async ({textDocument}: DocumentLinkParams): Promise => { const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)); - return documentLinks(documents.get(textDocument.uri)!, repoContext?.workspaceUri); + return documentLinks(getDocument(documents, textDocument), repoContext?.workspaceUri); }); // Make the text document manager listen on the connection @@ -176,3 +171,9 @@ export function initConnection(connection: Connection) { // Listen on the connection connection.listen(); } + +function getDocument(documents: TextDocuments, id: TextDocumentIdentifier): TextDocument { + // The text document manager should ensure all documents exist + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return documents.get(id.uri)!; +} diff --git a/languageserver/src/context-providers.ts b/languageserver/src/context-providers.ts index b8ce462..d9e880c 100644 --- a/languageserver/src/context-providers.ts +++ b/languageserver/src/context-providers.ts @@ -15,7 +15,7 @@ export function contextProviders( cache: TTLCache ): ContextProviderConfig { if (!repo || !client) { - return {getContext: (_: string) => Promise.resolve(undefined)}; + return {getContext: () => Promise.resolve(undefined)}; } const getContext = async ( diff --git a/languageserver/src/value-providers.ts b/languageserver/src/value-providers.ts index f8245e0..ca6a26d 100644 --- a/languageserver/src/value-providers.ts +++ b/languageserver/src/value-providers.ts @@ -21,16 +21,16 @@ export function valueProviders( "job-environment": { kind: ValueProviderKind.AllowedValues, caseInsensitive: true, - get: (_: WorkflowContext) => getEnvironments(client, cache, repo.owner, repo.name) + get: () => getEnvironments(client, cache, repo.owner, repo.name) }, "job-environment-name": { kind: ValueProviderKind.AllowedValues, caseInsensitive: true, - get: (_: WorkflowContext) => getEnvironments(client, cache, repo.owner, repo.name) + get: () => getEnvironments(client, cache, repo.owner, repo.name) }, "runs-on": { kind: ValueProviderKind.SuggestedValues, - get: (_: WorkflowContext) => getRunnerLabels(client, cache, repo.owner, repo.name) + get: () => getRunnerLabels(client, cache, repo.owner, repo.name) }, "step-with": { kind: ValueProviderKind.AllowedValues,