diff --git a/server/src/connectionHandlers/onCodeLens.ts b/server/src/connectionHandlers/onCodeLens.ts new file mode 100644 index 00000000..65760eab --- /dev/null +++ b/server/src/connectionHandlers/onCodeLens.ts @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------------------------- + * Copyright (c) 2023 Savoir-faire Linux. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * ------------------------------------------------------------------------------------------ */ + +import * as LSP from 'vscode-languageserver/node' +import { analyzer } from '../tree-sitter/analyzer' + +export async function onCodeLensHandler (params: LSP.CodeLensParams, enableCodeLensReferencesOnFunctions: boolean): Promise { + const codeLenses: LSP.CodeLens[] = [] + const uri = params.textDocument.uri + + if (!enableCodeLensReferencesOnFunctions) { + return [] + } + + const allSymbols = analyzer.getGlobalDeclarationSymbolsForUri(uri) + allSymbols.forEach((symbol) => { + if (symbol.kind === LSP.SymbolKind.Function) { + const codeLens = LSP.CodeLens.create(symbol.location.range) + + codeLens.command = { + title: 'Show References', + command: 'bitbake.codeLens.showReferences', + arguments: [uri, symbol.location.range.start] + } + + codeLens.data = { uri, position: symbol.location.range.start } + + codeLenses.push(codeLens) + } + }) + return codeLenses +} + +export function onCodeLensResolveHandler (codeLens: LSP.CodeLens): LSP.CodeLens { + return codeLens +} diff --git a/server/src/server.ts b/server/src/server.ts index 59e9db8e..115deba0 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -36,6 +36,7 @@ import { expandSettingPath } from './lib/src/BitbakeSettings' import { onReferenceHandler } from './connectionHandlers/onReference' import { type BitbakeScanResult } from './lib/src/types/BitbakeScanResult' import { onPrepareRenameHandler, onRenameRequestHandler } from './connectionHandlers/onRename' +import { onCodeLensHandler, onCodeLensResolveHandler } from './connectionHandlers/onCodeLens' // Create a connection for the server. The connection uses Node's IPC as a transport export const connection: Connection = createConnection(ProposedFeatures.all) @@ -161,36 +162,11 @@ disposables.push( analyzer.clearRecipeLocalFiles() }), - connection.onCodeLens(async (params): Promise => { - const codeLenses: LSP.CodeLens[] = [] - const uri = params.textDocument.uri - - if (!enableCodeLensReferencesOnFunctions) { - return [] - } - - const allSymbols = analyzer.getGlobalDeclarationSymbolsForUri(uri) - allSymbols.forEach((symbol) => { - if (symbol.kind === LSP.SymbolKind.Function) { - const codeLens = LSP.CodeLens.create(symbol.location.range) - - codeLens.command = { - title: 'Show References', - command: 'bitbake.codeLens.showReferences', - arguments: [uri, symbol.location.range.start] - } - - codeLens.data = { uri, position: symbol.location.range.start } - - codeLenses.push(codeLens) - } - }) - return codeLenses - }), + connection.onCodeLens( + async (params) => await onCodeLensHandler(params, enableCodeLensReferencesOnFunctions) + ), - connection.onCodeLensResolve((codeLens): LSP.CodeLens => { - return codeLens - }), + connection.onCodeLensResolve(onCodeLensResolveHandler), connection.onRequest( RequestMethod.EmbeddedLanguageTypeOnPosition,