Skip to content

Commit

Permalink
Use status bar message for lsp initialization
Browse files Browse the repository at this point in the history
Close #974.
Refactor lsp functions from debugger decorations module into lsp module.
  • Loading branch information
bpringe committed Jan 21, 2021
1 parent 365e3fd commit 4e9bd66
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 2 additions & 24 deletions src/debugger/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,6 @@ const instrumentedFunctionDecorationType = vscode.window.createTextEditorDecorat
}
});

async function getReferences(lspClient: LanguageClient, uri: string, position: Position): Promise<Location[] | null> {
const result: Location[] = await lspClient.sendRequest('textDocument/references', {
textDocument: {
uri,
},
position,
context: {
includeDeclaration: true
}
});
return result;
}

async function getDocumentSymbols(lspClient: LanguageClient, uri: string): Promise<DocumentSymbol[]> {
const result: DocumentSymbol[] = await lspClient.sendRequest('textDocument/documentSymbol', {
textDocument: {
uri
}
});
return result;
}

async function update(editor: vscode.TextEditor, cljSession: NReplSession, lspClient: LanguageClient): Promise<void> {
if (/(\.clj)$/.test(editor.document.fileName)) {
if (cljSession && util.getConnectedState() && lspClient) {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
47 changes: 32 additions & 15 deletions src/lsp.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -218,25 +218,18 @@ function registerEventHandlers(context: vscode.ExtensionContext, client: Languag
}));
}

function activate(context: vscode.ExtensionContext): Thenable<void> {
async function activate(context: vscode.ExtensionContext): Promise<void> {
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<void> {
Expand All @@ -247,8 +240,32 @@ function deactivate(): Promise<void> {
return Promise.resolve();
}

async function getReferences(lspClient: LanguageClient, uri: string, position: Position): Promise<Location[] | null> {
const result: Location[] = await lspClient.sendRequest('textDocument/references', {
textDocument: {
uri,
},
position,
context: {
includeDeclaration: true
}
});
return result;
}

async function getDocumentSymbols(lspClient: LanguageClient, uri: string): Promise<DocumentSymbol[]> {
const result: DocumentSymbol[] = await lspClient.sendRequest('textDocument/documentSymbol', {
textDocument: {
uri
}
});
return result;
}

export default {
activate,
deactivate,
LSP_CLIENT_KEY
LSP_CLIENT_KEY,
getReferences,
getDocumentSymbols
}

0 comments on commit 4e9bd66

Please sign in to comment.