forked from diem/move
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[move] Language server initialization
Implement language server initialization and an event loop in the move-analyzer language server executable. In tandem, implement a client for the server in the move-analyzer VS Code extension. For now, the server only advertises a single capability: "go to definition." This capability causes VS Code to display a "go to definition" command option when users have the move-analyzer extension installed. However, for now, when that option is used, the server panics (implementing a response is a "TODO"). However, despite the panic, several "features" are added as part of this commit: users of the VS Code extension will see logs in their "Move Analyzer Client" and "Move Language Server" output channels indicating that the client and server have initialized and connected to one another. Closes: #9463
- Loading branch information
1 parent
1b54bf4
commit 084d391
Showing
11 changed files
with
340 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,29 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Configuration } from './configuration'; | ||
import { Context } from './context'; | ||
import * as child_process from 'child_process'; | ||
import * as assert from 'assert'; | ||
import * as vscode from 'vscode'; | ||
|
||
/** | ||
* An extension command that displays the version of the server that this extension | ||
* interfaces with. | ||
*/ | ||
async function serverVersion(context: Readonly<Context>): Promise<void> { | ||
const version = child_process.spawnSync( | ||
context.configuration.serverPath, ['--version'], { encoding: 'utf8' }, | ||
); | ||
if (version.stdout) { | ||
await vscode.window.showInformationMessage(version.stdout); | ||
} else if (version.error) { | ||
await vscode.window.showErrorMessage( | ||
`Could not execute move-analyzer: ${version.error.message}.`, | ||
); | ||
} else { | ||
await vscode.window.showErrorMessage( | ||
`A problem occurred when executing '${context.configuration.serverPath}'.`, | ||
); | ||
} | ||
} | ||
/** Information related to this extension itself, such as its identifier and version. */ | ||
export class Extension { | ||
/** The string used to uniquely identify this particular extension to VS Code. */ | ||
readonly identifier = 'move.move-analyzer'; | ||
|
||
/** | ||
* The entry point to this VS Code extension. | ||
* | ||
* As per [the VS Code documentation on activation | ||
* events](https://code.visualstudio.com/api/references/activation-events), "an extension must | ||
* export an `activate()` function from its main module and it will be invoked only once by | ||
* VS Code when any of the specified activation events [are] emitted." | ||
* | ||
* Activation events for this extension are listed in its `package.json` file, under the key | ||
* `"activationEvents"`. | ||
*/ | ||
export function activate(extensionContext: Readonly<vscode.ExtensionContext>): void { | ||
const configuration = new Configuration(); | ||
const context = Context.create(extensionContext, configuration); | ||
if (context instanceof Error) { | ||
void vscode.window.showErrorMessage( | ||
`Could not activate move-analyzer: ${context.message}.`, | ||
); | ||
return; | ||
private readonly extension: vscode.Extension<unknown>; | ||
|
||
constructor() { | ||
const extension = vscode.extensions.getExtension(this.identifier); | ||
assert(extension !== undefined, `extension ${this.identifier} is not available`); | ||
this.extension = extension; | ||
} | ||
|
||
context.registerCommand('serverVersion', serverVersion); | ||
/** The version string. */ | ||
get version(): string { | ||
for (const entry of Object.entries(this.extension.packageJSON)) { | ||
if (entry[0] === 'version') { | ||
return entry[1] as string; | ||
} | ||
} | ||
return 'unknown'; | ||
} | ||
} |
Oops, something went wrong.