forked from move-language/move
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `--version` option to the `move-analyzer` executable, and a command to display the version to the Visual Studio extension. To do so: * Add a method of configuring the location of the `move-analyzer` executable that the extension interfaces with. * Add a programmatic entry point to the extension (previously the extension was just a static grammar file and programmatic tests). Other small improvements include: * Add a linter for TypeScript documentation. * Update the versions of the Node dependencies used by the VS Code extension. * Tweak linter settings -- in particular, ignore readonly parameter warnings since VS Code's API provides many mutable types. Closes: #9405
- Loading branch information
1 parent
411b76b
commit bf68a39
Showing
11 changed files
with
477 additions
and
282 deletions.
There are no files selected for viewing
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
543 changes: 279 additions & 264 deletions
543
language/move-analyzer/editors/code/package-lock.json
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as os from 'os'; | ||
import * as vscode from 'vscode'; | ||
|
||
/** | ||
* User-defined configuration values, such as those specified in VS Code settings. | ||
* | ||
* This provides a more strongly typed interface to the configuration values specified in this | ||
* extension's `package.json`, under the key `"contributes.configuration.properties"`. | ||
*/ | ||
export class Configuration { | ||
private readonly configuration: vscode.WorkspaceConfiguration; | ||
|
||
constructor() { | ||
this.configuration = vscode.workspace.getConfiguration('move-analyzer'); | ||
} | ||
|
||
/** The path to the move-analyzer executable. */ | ||
get serverPath(): string { | ||
const path = this.configuration.get<string>('server.path', 'move-analyzer'); | ||
if (path.startsWith('~/')) { | ||
return os.homedir() + path.slice('~'.length); | ||
} | ||
return path; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { Configuration } from './configuration'; | ||
import * as fs from 'fs'; | ||
import * as vscode from 'vscode'; | ||
|
||
/** Information passed along to each VS Code command defined by this extension. */ | ||
export class Context { | ||
private constructor( | ||
private readonly extension: Readonly<vscode.ExtensionContext>, | ||
readonly configuration: Readonly<Configuration>, | ||
) { } | ||
|
||
static create( | ||
extension: Readonly<vscode.ExtensionContext>, | ||
configuration: Readonly<Configuration>, | ||
): Context | Error { | ||
if (!fs.existsSync(configuration.serverPath)) { | ||
return new Error(`command '${configuration.serverPath}' could not be found.`); | ||
} | ||
return new Context(extension, configuration); | ||
} | ||
|
||
/** | ||
* Registers the given command with VS Code. | ||
* | ||
* "Registering" the function means that the VS Code machinery will execute it when the command | ||
* with the given name is requested by the user. The command names themselves are specified in | ||
* this extension's `package.json` file, under the key `"contributes.commands"`. | ||
*/ | ||
registerCommand( | ||
name: Readonly<string>, | ||
command: (context: Readonly<Context>) => Promise<void>, | ||
): void { | ||
const disposable = vscode.commands.registerCommand(`move-analyzer.${name}`, async () => { | ||
return command(this); | ||
}); | ||
this.extension.subscriptions.push(disposable); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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 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}'.`, | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
context.registerCommand('serverVersion', serverVersion); | ||
} |
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,6 +1,13 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use structopt::StructOpt; | ||
|
||
#[derive(StructOpt)] | ||
#[structopt(name = "move-analyzer", about = "A language server for Move")] | ||
struct Options {} | ||
|
||
fn main() { | ||
Options::from_args(); | ||
todo!() | ||
} |