Merge pull request #197 from github/joshmgross/lint-language-server-part-two
Lint the language server package
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
HoverParams,
|
HoverParams,
|
||||||
InitializeParams,
|
InitializeParams,
|
||||||
InitializeResult,
|
InitializeResult,
|
||||||
|
TextDocumentIdentifier,
|
||||||
TextDocumentPositionParams,
|
TextDocumentPositionParams,
|
||||||
TextDocuments,
|
TextDocuments,
|
||||||
TextDocumentSyncKind
|
TextDocumentSyncKind
|
||||||
@@ -38,7 +39,6 @@ export function initConnection(connection: Connection) {
|
|||||||
const cache = new TTLCache();
|
const cache = new TTLCache();
|
||||||
|
|
||||||
let hasWorkspaceFolderCapability = false;
|
let hasWorkspaceFolderCapability = false;
|
||||||
let hasDiagnosticRelatedInformationCapability = false;
|
|
||||||
|
|
||||||
// Register remote console logger with language service
|
// Register remote console logger with language service
|
||||||
registerLogger(connection.console);
|
registerLogger(connection.console);
|
||||||
@@ -47,13 +47,8 @@ export function initConnection(connection: Connection) {
|
|||||||
const capabilities = params.capabilities;
|
const capabilities = params.capabilities;
|
||||||
|
|
||||||
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
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) {
|
if (options.sessionToken) {
|
||||||
client = getClient(options.sessionToken, options.userAgent);
|
client = getClient(options.sessionToken, options.userAgent);
|
||||||
@@ -94,7 +89,7 @@ export function initConnection(connection: Connection) {
|
|||||||
|
|
||||||
connection.onInitialized(() => {
|
connection.onInitialized(() => {
|
||||||
if (hasWorkspaceFolderCapability) {
|
if (hasWorkspaceFolderCapability) {
|
||||||
connection.workspace.onDidChangeWorkspaceFolders(_event => {
|
connection.workspace.onDidChangeWorkspaceFolders(() => {
|
||||||
clearCache();
|
clearCache();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -136,7 +131,7 @@ export function initConnection(connection: Connection) {
|
|||||||
await onCompletion(
|
await onCompletion(
|
||||||
connection,
|
connection,
|
||||||
position,
|
position,
|
||||||
documents.get(textDocument.uri)!,
|
getDocument(documents, textDocument),
|
||||||
client,
|
client,
|
||||||
repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)),
|
repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri)),
|
||||||
cache
|
cache
|
||||||
@@ -147,7 +142,7 @@ export function initConnection(connection: Connection) {
|
|||||||
connection.onHover(async ({position, textDocument}: HoverParams): Promise<Hover | null> => {
|
connection.onHover(async ({position, textDocument}: HoverParams): Promise<Hover | null> => {
|
||||||
return timeOperation("hover", async () => {
|
return timeOperation("hover", async () => {
|
||||||
const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri));
|
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),
|
descriptionProvider: descriptionProvider(client, cache),
|
||||||
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache),
|
contextProviderConfig: repoContext && contextProviders(client, repoContext, cache),
|
||||||
fileProvider: getFileProvider(client, cache, repoContext?.workspaceUri, async path => {
|
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) {
|
if (params.command === Commands.ClearCache) {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
documents.all().forEach(validateTextDocument);
|
await Promise.all(documents.all().map(doc => validateTextDocument(doc)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.onDocumentLinks(async ({textDocument}: DocumentLinkParams): Promise<DocumentLink[] | null> => {
|
connection.onDocumentLinks(async ({textDocument}: DocumentLinkParams): Promise<DocumentLink[] | null> => {
|
||||||
const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri));
|
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
|
// Make the text document manager listen on the connection
|
||||||
@@ -176,3 +171,9 @@ export function initConnection(connection: Connection) {
|
|||||||
// Listen on the connection
|
// Listen on the connection
|
||||||
connection.listen();
|
connection.listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDocument(documents: TextDocuments<TextDocument>, 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)!;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function contextProviders(
|
|||||||
cache: TTLCache
|
cache: TTLCache
|
||||||
): ContextProviderConfig {
|
): ContextProviderConfig {
|
||||||
if (!repo || !client) {
|
if (!repo || !client) {
|
||||||
return {getContext: (_: string) => Promise.resolve(undefined)};
|
return {getContext: () => Promise.resolve(undefined)};
|
||||||
}
|
}
|
||||||
|
|
||||||
const getContext = async (
|
const getContext = async (
|
||||||
|
|||||||
@@ -21,16 +21,16 @@ export function valueProviders(
|
|||||||
"job-environment": {
|
"job-environment": {
|
||||||
kind: ValueProviderKind.AllowedValues,
|
kind: ValueProviderKind.AllowedValues,
|
||||||
caseInsensitive: true,
|
caseInsensitive: true,
|
||||||
get: (_: WorkflowContext) => getEnvironments(client, cache, repo.owner, repo.name)
|
get: () => getEnvironments(client, cache, repo.owner, repo.name)
|
||||||
},
|
},
|
||||||
"job-environment-name": {
|
"job-environment-name": {
|
||||||
kind: ValueProviderKind.AllowedValues,
|
kind: ValueProviderKind.AllowedValues,
|
||||||
caseInsensitive: true,
|
caseInsensitive: true,
|
||||||
get: (_: WorkflowContext) => getEnvironments(client, cache, repo.owner, repo.name)
|
get: () => getEnvironments(client, cache, repo.owner, repo.name)
|
||||||
},
|
},
|
||||||
"runs-on": {
|
"runs-on": {
|
||||||
kind: ValueProviderKind.SuggestedValues,
|
kind: ValueProviderKind.SuggestedValues,
|
||||||
get: (_: WorkflowContext) => getRunnerLabels(client, cache, repo.owner, repo.name)
|
get: () => getRunnerLabels(client, cache, repo.owner, repo.name)
|
||||||
},
|
},
|
||||||
"step-with": {
|
"step-with": {
|
||||||
kind: ValueProviderKind.AllowedValues,
|
kind: ValueProviderKind.AllowedValues,
|
||||||
|
|||||||
Reference in New Issue
Block a user