From 4e9bd660272e8e46e75f84cf4a8c40b29006cb1d Mon Sep 17 00:00:00 2001 From: Brandon Ringe Date: Thu, 21 Jan 2021 10:58:47 -0800 Subject: [PATCH] Use status bar message for lsp initialization Close #974. Refactor lsp functions from debugger decorations module into lsp module. --- CHANGELOG.md | 1 + src/debugger/decorations.ts | 26 ++------------------ src/lsp.ts | 47 +++++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02dbaa1fd..ed9a90145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Changes to Calva. ## [Unreleased] +- [Use status bar message instead of withProgress message for clojure-lsp initialization](https://github.com/BetterThanTomorrow/calva/issues/974) - [Update cider-nrepl: 0.25.6 -> 0.25.7](https://github.com/BetterThanTomorrow/calva/issues/973) - Fix: ["Extract function" refactoring doesn't work as expected with selections](https://github.com/BetterThanTomorrow/calva/issues/958) diff --git a/src/debugger/decorations.ts b/src/debugger/decorations.ts index 3705e7387..d02b0effa 100644 --- a/src/debugger/decorations.ts +++ b/src/debugger/decorations.ts @@ -31,28 +31,6 @@ const instrumentedFunctionDecorationType = vscode.window.createTextEditorDecorat } }); -async function getReferences(lspClient: LanguageClient, uri: string, position: Position): Promise { - const result: Location[] = await lspClient.sendRequest('textDocument/references', { - textDocument: { - uri, - }, - position, - context: { - includeDeclaration: true - } - }); - return result; -} - -async function getDocumentSymbols(lspClient: LanguageClient, uri: string): Promise { - const result: DocumentSymbol[] = await lspClient.sendRequest('textDocument/documentSymbol', { - textDocument: { - uri - } - }); - return result; -} - async function update(editor: vscode.TextEditor, cljSession: NReplSession, lspClient: LanguageClient): Promise { if (/(\.clj)$/.test(editor.document.fileName)) { if (cljSession && util.getConnectedState() && lspClient) { @@ -66,7 +44,7 @@ async function update(editor: vscode.TextEditor, cljSession: NReplSession, lspCl // Find locations of instrumented symbols const documentUri = document.uri.toString(); - const documentSymbols = await getDocumentSymbols(lspClient, documentUri); + const documentSymbols = await lsp.getDocumentSymbols(lspClient, documentUri); const instrumentedSymbolsInEditor = documentSymbols[0].children.filter(s => instrumentedDefsInEditor.includes(s.name)); // Find locations of instrumented symbol references @@ -75,7 +53,7 @@ async function update(editor: vscode.TextEditor, cljSession: NReplSession, lspCl line: s.range.start.line, character: s.range.start.character }; - return getReferences(lspClient, documentUri, position); + return lsp.getReferences(lspClient, documentUri, position); })); const currentNamespaceSymbolReferenceLocations = instrumentedSymbolsInEditor.reduce((currentLocations, symbol, i) => { return { diff --git a/src/lsp.ts b/src/lsp.ts index 39c413fc6..6840375d5 100644 --- a/src/lsp.ts +++ b/src/lsp.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import { LanguageClient, ServerOptions, LanguageClientOptions } from 'vscode-languageclient'; +import { LanguageClient, ServerOptions, LanguageClientOptions, DocumentSymbol, Position } from 'vscode-languageclient'; import * as path from 'path'; import * as state from './state'; import * as util from './utilities' @@ -218,25 +218,18 @@ function registerEventHandlers(context: vscode.ExtensionContext, client: Languag })); } -function activate(context: vscode.ExtensionContext): Thenable { +async function activate(context: vscode.ExtensionContext): Promise { const jarPath = path.join(context.extensionPath, 'clojure-lsp.jar'); const client = createClient(jarPath); registerCommands(context, client); registerEventHandlers(context, client); - return new Promise((resolveLspActivation, _rejectLspActivation) => { - vscode.window.withProgress({ - location: vscode.ProgressLocation.Notification, - title: "clojure-lsp starting. You don't need to wait for it to start using Calva. Please go ahead with Jack-in or Connect to the REPL. See https://calva.io/clojure-lsp for more info.", - cancellable: false - }, async (_progress, _token) => { - await client.onReady(); - state.cursor.set(LSP_CLIENT_KEY, client); - resolveLspActivation(); - }); - client.start(); - }); + vscode.window.setStatusBarMessage('$(sync~spin) Initializing Clojure language features', client.onReady()); + + client.start(); + await client.onReady(); + state.cursor.set(LSP_CLIENT_KEY, client); } function deactivate(): Promise { @@ -247,8 +240,32 @@ function deactivate(): Promise { return Promise.resolve(); } +async function getReferences(lspClient: LanguageClient, uri: string, position: Position): Promise { + const result: Location[] = await lspClient.sendRequest('textDocument/references', { + textDocument: { + uri, + }, + position, + context: { + includeDeclaration: true + } + }); + return result; +} + +async function getDocumentSymbols(lspClient: LanguageClient, uri: string): Promise { + const result: DocumentSymbol[] = await lspClient.sendRequest('textDocument/documentSymbol', { + textDocument: { + uri + } + }); + return result; +} + export default { activate, deactivate, - LSP_CLIENT_KEY + LSP_CLIENT_KEY, + getReferences, + getDocumentSymbols } \ No newline at end of file