Skip to content

Commit

Permalink
Refresh CodeLens using LSP request instead of document document modif…
Browse files Browse the repository at this point in the history
…y trick
  • Loading branch information
jribbink committed May 5, 2023
1 parent 6a19ed5 commit 3cc888d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
9 changes: 8 additions & 1 deletion extension/src/emulator/server/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Mutex } from 'async-mutex'
import { exec } from 'child_process'
import { verifyEmulator } from '../local/emulatorScanner'
import { delay } from '../../utils/utils'
import { CodeLensParams, CodeLensRequest, ExecuteCommandRequest, TextDocumentIdentifier } from 'vscode-languageclient'

// Identities for commands handled by the Language server
const CREATE_ACCOUNT_SERVER = 'cadence.server.flow.createAccount'
Expand Down Expand Up @@ -155,12 +156,18 @@ export class LanguageServerAPI {
}

async #sendRequest (cmd: string, args: any[] = []): Promise<any> {
return await this.client?.sendRequest('workspace/executeCommand', {
return await this.client?.sendRequest(ExecuteCommandRequest.type, {
command: cmd,
arguments: args
})
}

async refreshCodeLens () {
const textDocumentUri = window.activeTextEditor?.document.uri
if (textDocumentUri == null) return
return await this.client?.sendRequest(CodeLensRequest.type, <CodeLensParams>{ textDocument: TextDocumentIdentifier.create(textDocumentUri.path) })
}

async reset (): Promise<void> {
const enableFlow = await verifyEmulator()
await this.restart(enableFlow)
Expand Down
3 changes: 1 addition & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* The extension */
import { EmulatorState, EmulatorController } from './emulator/emulator-controller'
import { CommandController } from './commands/command-controller'
import { refreshCodeLenses } from './utils/codelens'
import { Account } from './emulator/account'
import { UIController } from './ui/ui-controller'
import { ExtensionContext } from 'vscode'
Expand Down Expand Up @@ -69,7 +68,7 @@ export class Extension {

// Update UI
this.#uiCtrl.emulatorStateChanged()
refreshCodeLenses()
this.emulatorCtrl.api.refreshCodeLens()
}

checkDependencies (): void {
Expand Down
23 changes: 0 additions & 23 deletions extension/src/utils/codelens.ts

This file was deleted.

0 comments on commit 3cc888d

Please sign in to comment.