Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

[move-analyzer] Support document symbol PSL #218

Merged
merged 98 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
79d4d64
feat: add release workflow
yubing744 Jun 17, 2022
166bd9c
feat: update release script
yubing744 Jun 17, 2022
1c16bcc
feat: update release
yubing744 Jun 17, 2022
4f940bc
feat: fmt release.sh
yubing744 Jun 18, 2022
ce9ec8a
feat: add lsp.test.ts for move-analyzer
yubing744 Jun 18, 2022
9cd389b
feat: fix copyfiles error
yubing744 Jun 19, 2022
c9f13e7
feat: config test for lsp
yubing744 Jun 19, 2022
6efd3bf
feat: ok for lsp test
yubing744 Jun 20, 2022
254cd9c
feat: get symbols from table
yubing744 Jun 20, 2022
c74bfff
feat: export symbols
yubing744 Jun 21, 2022
5809291
feat: test textDocument/documentSymbol
yubing744 Jun 21, 2022
a8f6997
feat: re impl symbols
yubing744 Jun 22, 2022
3bb4356
feat: parse symbols tree
yubing744 Jun 22, 2022
b008c1a
feat: ok for on_document_symbol_request
yubing744 Jun 23, 2022
e74bceb
feat: merge from main
yubing744 Jun 23, 2022
000b9a3
feat: auto build move-analyzer and set default for serverPath
yubing744 Jun 23, 2022
f53f2cc
feat: fix ci check fail
yubing744 Jun 23, 2022
35476e9
feat: fix ci check error
yubing744 Jun 23, 2022
09ef64d
feat: fix lint error
yubing744 Jun 23, 2022
6f87de5
feat: merge from upsteam main
yubing744 Jun 24, 2022
ea8761b
fix: fix lsp test fail
yubing744 Jun 24, 2022
43fea39
feat: fmt move-analyzer code
yubing744 Jun 24, 2022
179708e
feat: fix lsp fisrt test error
yubing744 Jun 24, 2022
a479ee7
feat: update timeout for move-analyzer active
yubing744 Jun 24, 2022
bfbe898
feat: support events
yubing744 Jun 24, 2022
c863d2f
fix: fix error for LSP test
yubing744 Jun 25, 2022
945ead0
feat: merge from main
yubing744 Jun 25, 2022
71e3900
feat: fix bug for merge from master
yubing744 Jun 25, 2022
b682cd0
feat: fmt code
yubing744 Jun 25, 2022
3558e5d
Merge branch 'support-document-symbol-psl-3' into support-document-sy…
yubing744 Jun 25, 2022
b817b02
feat: update test and igonre package-lock.json for broken url test
yubing744 Jun 25, 2022
081f93e
feat: change name for ready events
yubing744 Jun 25, 2022
0be56e1
Merge branch 'support-document-symbol-psl-3' into support-document-sy…
yubing744 Jun 25, 2022
72c3cb6
feat: remove unrelate code
yubing744 Jun 26, 2022
07c9b97
feat: remove yarn.lock
yubing744 Jun 26, 2022
b006e8f
feat: ignore yarn.lock and recover configuration.ts
yubing744 Jun 26, 2022
1a19071
feat: update the comment for OnReady
yubing744 Jun 26, 2022
be3090a
Merge branch 'main' of https://github.com/move-language/move into sup…
yubing744 Jun 26, 2022
33c45fd
Merge branch 'support-document-symbol-psl-3' into support-document-sy…
yubing744 Jun 26, 2022
5ffa26e
feat: merge from main
yubing744 Jun 28, 2022
a3ab0bd
feat: remove codes
yubing744 Jun 28, 2022
b33ffce
feat: lock file
yubing744 Jun 29, 2022
023b6da
feat: add waiting code
yubing744 Jun 30, 2022
96cbf9e
feat: try lock code
yubing744 Jul 1, 2022
021c713
feat: test new way
yubing744 Jul 2, 2022
9ce1851
feat: ok for symbols
yubing744 Jul 3, 2022
b6897a4
feat: merge from main
yubing744 Jul 3, 2022
09d482f
feat: fix ci-check issue
yubing744 Jul 3, 2022
a05eeac
feat: update ci-check issues
yubing744 Jul 3, 2022
ecebbc6
feat: fix ci-check issues
yubing744 Jul 3, 2022
d623b21
Merge branch 'support-document-symbol-psl-5' into support-document-sy…
yubing744 Jul 3, 2022
00ee707
[Move analyzer] Added support for computing first symbol info synchro…
awelc Jul 11, 2022
998e630
Merge branch 'aw/move-analyzer-sync-start' of https://github.com/awel…
yubing744 Jul 13, 2022
edd291d
feat: handle symbols on start
yubing744 Jul 13, 2022
73d4c73
Merge branch 'main' into support-document-symbol-psl-6
yubing744 Jul 13, 2022
44ac909
feat: remove unuse code
yubing744 Jul 13, 2022
a1458e8
feat: format code
yubing744 Jul 13, 2022
2242869
Merge branch 'support-document-symbol-psl-6' into support-document-sy…
yubing744 Jul 13, 2022
9016aa3
feat: add test for mac and windows platform
yubing744 Jul 18, 2022
1cc7245
feat: fix bug for uri to path
yubing744 Jul 19, 2022
b8ea9ac
feat: fixbug for windows platform get_symbols stack overflow
yubing744 Jul 20, 2022
21697b0
feat: fixbug for reporting lsp diagnostics
yubing744 Jul 20, 2022
b149aee
feat: merge from main
yubing744 Jul 23, 2022
1e62ec3
feat: fixbug for windows test
yubing744 Jul 24, 2022
8d4e3d6
feat: fix lint error for language/move-analyzer/src/symbols.rs
yubing744 Jul 24, 2022
f56bb60
feat: remove config for windows stack
yubing744 Jul 24, 2022
2ad1510
feat: update pipeline for move-analyzer
yubing744 Jul 24, 2022
66d7d5a
feat: change name for test-move-analyzer-vscode-extension
yubing744 Jul 24, 2022
23c4da1
feat: remove tsfmt for windows check fail
yubing744 Jul 24, 2022
78f15cb
Merge branch 'support-document-symbol-psl-7' into support-document-sy…
yubing744 Jul 24, 2022
0660448
feat: fixbug for stack overflow and lint error
yubing744 Jul 24, 2022
33caa51
feat: fix lint error
yubing744 Jul 24, 2022
b564f72
feat: add commit for linebreak-style
yubing744 Jul 24, 2022
c4f76b9
Merge branch 'support-document-symbol-psl-8' into support-document-sy…
yubing744 Jul 24, 2022
4332a4f
feat: fix code review issue
yubing744 Jul 26, 2022
761a77b
Merge branch 'main' of https://github.com/move-language/move into sup…
yubing744 Jul 26, 2022
df1a545
feat: remove linkarg config
yubing744 Jul 26, 2022
bc250ea
feat: update cargo/config fmt
yubing744 Jul 26, 2022
4753dd8
Merge branch 'support-document-symbol-psl-9' into support-document-sy…
yubing744 Jul 26, 2022
7c55136
feat: config move-analyzer test vscode version to 1.69.2
yubing744 Jul 27, 2022
1f2dce5
feat: add comments for plugin activate
yubing744 Jul 27, 2022
2b3f95f
feat: upgrate ci-test mac system to mac-11
yubing744 Jul 27, 2022
808e8c7
feat: update style issue
yubing744 Jul 27, 2022
b40fe1e
feat: fixbug for user data dir too long for 1.69.2
yubing744 Jul 28, 2022
8e534ed
feat: fixbug for userDataDir too long
yubing744 Jul 28, 2022
feffb26
Merge branch 'main' of https://github.com/move-language/move into sup…
yubing744 Jul 28, 2022
317618b
Merge branch 'support-document-symbol-psl-9' into support-document-sy…
yubing744 Jul 28, 2022
4ec7364
feat: fixbug for vsce package missing files
yubing744 Jul 29, 2022
4695277
feat: add feature in README.md
yubing744 Jul 31, 2022
49246f6
Merge branch 'main' of https://github.com/move-language/move into sup…
yubing744 Jul 31, 2022
ceefd18
feat: add comment for startClient func in context.ts
yubing744 Jul 31, 2022
0781331
feat: update package-lock.json
yubing744 Jul 31, 2022
078e528
feat: format context.ts
yubing744 Jul 31, 2022
bfcac5e
feat: update package-lock.json for move-analyzer
yubing744 Jul 31, 2022
253e656
feat: format context.ts
yubing744 Jul 31, 2022
95c0545
Merge branch 'support-document-symbol-psl-10' into support-document-s…
yubing744 Jul 31, 2022
6d1b88f
feat: add outline feature detail descripe
yubing744 Jul 31, 2022
2af17df
feat: format README
yubing744 Aug 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-pre-land.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ jobs:
- prepare
steps:
- uses: actions/[email protected]
- name: install rust toolchain
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmwill, I was hoping that you could take a look at the changes in this file...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not obvious to me why the rust toolchain needs to get installed to be able to build a JS package

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can at least try to respond to this one. The extended testing introduced in this PR involves the plugin (VSCode side) talking to the language server (which is written in Rust and presumably we need Rust tool chain to build its binary).

uses: actions-rs/toolchain@v1
- name: Use Node.js 14
uses: actions/[email protected]
with:
Expand Down Expand Up @@ -257,7 +259,7 @@ jobs:
gem install awesome_bot
# Don't look in git or target dirs. Don't check png, bib, tex, js, or shell files
# We allow links to be redirects, allow duplicates, and we also allow Too Many Requests (429) errors
find . -not \( -path "./.git*" -prune \) -not \( -path "./target" -prune \) -type f -not -name "*.png" -not -name "*.sh" -not -name "*.bib" -not -name "*.tex" -not -name "*.js" | while read arg; do awesome_bot --allow-redirect --allow-dupe --allow 429 --skip-save-results $arg; done
find . -not \( -path "./.git*" -prune \) -not \( -path "./target" -prune \) -type f -not -name "*.png" -not -name "*.sh" -not -name "*.bib" -not -name "*.tex" -not -name "*.js" -not -name "package-lock.json" | while read arg; do awesome_bot --allow-redirect --allow-dupe --allow 429 --skip-save-results $arg; done

build-move-cli-docker-image:
name: Build Docker image for the Move CLI
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions language/move-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ im = "15.1.0"
lsp-server = "0.5.1"
lsp-types = "0.90.1"
petgraph = "0.5.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.64"
tempfile = "3.2.0"
url = "2.2.2"
Expand Down
11 changes: 8 additions & 3 deletions language/move-analyzer/editors/code/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"max-len": [
"warn",
{
"code": 100,
"code": 120,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this changes and other eslint changes?

Copy link
Contributor Author

@yubing744 yubing744 Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a conflict between lint and fmt checks before, making it impossible to pass the check when setting 100, and the others were similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a conflict between lint and fmt checks before, making it impossible to pass the check when setting 100

I realized I did not actually submit the re-review comments that I put in last week, so here they are.

With respect to the stack overflow fix, I don't think it works if the binary is installed using cargo install --git https://...

I believe that the reason my "old" fix did not work was that I omitted the first symbolicator run (my bad...), which should be now fixed in #306

I tested your new PR and stack overflow problem solved

"ignoreUrls": true
}
],
Expand Down Expand Up @@ -206,10 +206,15 @@
],
"@typescript-eslint/strict-boolean-expressions": "warn",
"@typescript-eslint/switch-exhaustiveness-check": "warn",
"@typescript-eslint/type-annotation-spacing": "warn",
"@typescript-eslint/unified-signatures": "warn",

// The following are eslint-plugin-tsdoc rules:
"tsdoc/syntax": "warn"
"tsdoc/syntax": "warn",

"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/type-annotation-spacing": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/restrict-template-expressions": "off"
}
}
2 changes: 2 additions & 0 deletions language/move-analyzer/editors/code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ out
.vscode-test
# VS Code extension package (VSIX) archive
*.vsix
# Yarn cache directory
yarn.lock
11 changes: 7 additions & 4 deletions language/move-analyzer/editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@
}
},
"scripts": {
"compile": "tsc -p ./",
"compile": "tsc -p ./ && cd ../../ && cargo build",
"watch": "tsc -watch -p ./",
"lint": "tsfmt --verify && eslint . --ext ts --max-warnings 0",
"fix": "tsfmt --replace && eslint . --ext ts --fix",
"pretest": "npm run compile && npm run lint",
"copy-tests-files": "copyfiles \"tests/**/*.move\" \"tests/**/*.exp\" \"tests/**/*.toml\" \"tests/**/*.code-workspace\" out",
"pretest": "npm run compile && npm run lint && npm run copy-tests-files",
"test": "node ./out/tests/runTests.js",
"dev": "npm run pretest && mode=dev node ./out/tests/runTests.js",
"vscode:prepublish": "npm run pretest",
"package": "vsce package -o move-analyzer.vsix",
"publish": "npm run pretest && npm run test && vsce publish"
Expand All @@ -110,15 +112,16 @@
"@types/vscode": "^1.58.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vscode/test-electron": "^1.6.1",
"@vscode/test-electron": "^2.0.0",
"eslint": "^7.32.0",
"eslint-plugin-tsdoc": "^0.2.14",
"glob": "^7.1.7",
"mocha": "^9.1.1",
"typescript": "^4.4.4",
"typescript-formatter": "^7.2.2",
"vsce": "^2.5.1",
"vscode-test": "^1.6.1"
"vscode-test": "^1.6.1",
"copyfiles": "2.4.1"
},
"__metadata": {
"id": "71e74fc8-23c2-47b7-8594-ed00192d96a6",
Expand Down
1 change: 1 addition & 0 deletions language/move-analyzer/editors/code/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lsp_command';
17 changes: 17 additions & 0 deletions language/move-analyzer/editors/code/src/commands/lsp_command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stella3d, I was. hoping that you could take a look at the TS code in this PR, mostly at how idiomatic it is (I am not at TS expert I am afraid...).

import * as lc from 'vscode-languageclient';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type declarations of lc.* would be more idiomatic if directly used:

import { DocumentSymbolParams, SymbolInformation, DocumentSymbol } from vscode-languageclient
...

export async function textDocumentDocumentSymbol(context: Readonly<Context>, params: DocumentSymbolParams)

import type { Context } from '../context';

/**
* An LSP command textDocument/documentSymbol
*/
export async function textDocumentDocumentSymbol(context: Readonly<Context>, params: lc.DocumentSymbolParams)
: Promise<Array<lc.SymbolInformation> | Array<lc.DocumentSymbol> | null> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array<T> is more idiomatic as T[]

const client = context.getClient();
if (client === undefined) {
return Promise.reject(new Error('No language client connected.'));
}

// Send the request to the language client.
return client.sendRequest(lc.DocumentSymbolRequest.type, params);
}
3 changes: 2 additions & 1 deletion language/move-analyzer/editors/code/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as os from 'os';
import * as vscode from 'vscode';
import * as Path from 'path';

/**
* User-defined configuration values, such as those specified in VS Code settings.
Expand Down Expand Up @@ -36,6 +37,6 @@ export class Configuration {
if (path.startsWith('~/')) {
return os.homedir() + path.slice('~'.length);
}
return path;
return Path.resolve(path);
}
}
32 changes: 25 additions & 7 deletions language/move-analyzer/editors/code/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import { sync as commandExistsSync } from 'command-exists';

/** Information passed along to each VS Code command defined by this extension. */
export class Context {
private _client: lc.LanguageClient | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless required by the style guide in this repo, it's more idiomatic to rely on the private declaration without the _ prefix in the name


private constructor(
private readonly extensionContext: Readonly<vscode.ExtensionContext>,
readonly configuration: Readonly<Configuration>,
) { }
client: lc.LanguageClient | undefined = undefined,
) {
this._client = client;
}

static create(
extensionContext: Readonly<vscode.ExtensionContext>,
Expand All @@ -39,12 +44,14 @@ export class Context {
*/
registerCommand(
name: Readonly<string>,
command: (context: Readonly<Context>) => Promise<void>,
command: (context: Readonly<Context>, ...args: Array<any>) => any,
): void {
const disposable = vscode.commands.registerCommand(`move-analyzer.${name}`, async () => {
const com = await command(this);
return com;
const disposable = vscode.commands.registerCommand(`move-analyzer.${name}`, async (...args: Array<any>)
: Promise<any> => {
const ret = await command(this, ...args);
return ret;
});

this.extensionContext.subscriptions.push(disposable);
}

Expand All @@ -60,7 +67,7 @@ export class Context {
* To read more about the messages sent and responses received by this client, such as
* "initialize," read [the Language Server Protocol specification](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize).
**/
startClient(): void {
async startClient(): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this changes? In particular, why does startClient must be async now? If all this is necessary, please provide additional explanation in the comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or because ci-test needs to wait for the symbol table parsing to be completed synchronously, which requires that the activation of the plugin is also synchronous

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or because ci-test needs to wait for the symbol table parsing to be completed synchronously, which requires that the activation of the plugin is also synchronous

Well, if "the activation of the plugin is also synchronous" then why do we need async.

More generally, I am not a TS expert, and that's why I asked one of colleagues to look at the TS part of this PR, but still - a few more comments in code explaining what the additions to the TS code do would help (also with future maintenance).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any additional comment on this? I still do not understand why we need asynchrony. You yourself write that the symbol table parsing happens synchronously so why we need async code here?

const executable: lc.Executable = {
command: this.configuration.serverPath,
};
Expand Down Expand Up @@ -92,5 +99,16 @@ export class Context {
log.info('Starting client...');
const disposable = client.start();
this.extensionContext.subscriptions.push(disposable);
this._client = client;
await this._client.onReady();
}

/**
* Returns the client that this extension interacts with.
*
* @returns lc.LanguageClient
*/
getClient(): lc.LanguageClient | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless replacing the client after constructing is required, this could be replaced with a readonly property:
private _client becomes readonly client

return this._client;
}
}
} // Context
8 changes: 6 additions & 2 deletions language/move-analyzer/editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { Configuration } from './configuration';
import { Context } from './context';
import { Extension } from './extension';
import { log } from './log';

import * as childProcess from 'child_process';
import * as vscode from 'vscode';
import * as commands from './commands';


/**
* An extension command that displays the version of the server that this extension
Expand Down Expand Up @@ -41,7 +44,7 @@ async function serverVersion(context: Readonly<Context>): Promise<void> {
* Activation events for this extension are listed in its `package.json` file, under the key
* `"activationEvents"`.
*/
export function activate(extensionContext: Readonly<vscode.ExtensionContext>): void {
export async function activate(extensionContext: Readonly<vscode.ExtensionContext>): Promise<void> {
const extension = new Extension();
log.info(`${extension.identifier} version ${extension.version}`);

Expand All @@ -63,5 +66,6 @@ export function activate(extensionContext: Readonly<vscode.ExtensionContext>): v
context.registerCommand('serverVersion', serverVersion);

// All other utilities provided by this extension occur via the language server.
context.startClient();
await context.startClient();
context.registerCommand('textDocumentDocumentSymbol', commands.textDocumentDocumentSymbol);
}
8 changes: 8 additions & 0 deletions language/move-analyzer/editors/code/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import * as path from 'path';
/* eslint-disable */
// deno-lint-ignore require-await
export async function run(): Promise<void> {
// dev mode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My confusion about the changes to async continues without having additional explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized I did not actually submit the re-review comments that I put in last week, so here they are.

With respect to the stack overflow fix, I don't think it works if the binary is installed using cargo install --git https://...

I believe that the reason my "old" fix did not work was that I omitted the first symbolicator run (my bad...), which should be now fixed in #306

I will merge this new PR

const mode = process.env['mode'] || 'test';
if (mode === 'dev') {
return new Promise((resolve) => {
setTimeout(resolve, 1000 * 60 * 15); // 15分钟休息一下
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this comment to English.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

});
}

/* eslint-disable */
const suite = new Mocha({
ui: 'tdd',
Expand Down
9 changes: 9 additions & 0 deletions language/move-analyzer/editors/code/tests/lsp-demo/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "Symbols"
version = "0.0.1"

[dependencies]
MoveStdlib = { local = "../../../../../../move-stdlib/", addr_subst = { "std" = "0x1" } }

[addresses]
Symbols = "0xCAFE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"move-analyzer.server.path": "../../../../target/debug/move-analyzer"
}
}
18 changes: 18 additions & 0 deletions language/move-analyzer/editors/code/tests/lsp-demo/sources/M1.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Symbols::M1 {

const SOME_CONST: u64 = 42;

struct SomeOtherStruct has drop {
some_field: u64,
}

public fun some_other_struct(v: u64): SomeOtherStruct {
SomeOtherStruct { some_field: v }
}

#[test]
#[expected_failure]
fun this_is_a_test() {
1/0;
}
}
52 changes: 52 additions & 0 deletions language/move-analyzer/editors/code/tests/lsp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as assert from 'assert';
import * as Mocha from 'mocha';
import * as path from 'path';
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';

Mocha.suite('LSP', () => {
Mocha.test('textDocument/documentSymbol', async () => {
const ext = vscode.extensions.getExtension('move.move-analyzer');
assert.ok(ext);

await ext.activate();

// 1. get workdir
const workDir = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '';

// 2. open doc
const docs = await vscode.workspace.openTextDocument(path.join(workDir, 'sources/M1.move'));
await vscode.window.showTextDocument(docs);

// 3. execute command
const params: lc.DocumentSymbolParams = {
textDocument: {
uri: docs.uri.toString(),
},
};

const syms: Array<lc.DocumentSymbol> | undefined = await
vscode.commands.executeCommand(
'move-analyzer.textDocumentDocumentSymbol', params,
);

assert.ok(syms);
assert.deepStrictEqual(syms[0]?.kind, lc.SymbolKind.Module);
assert.deepStrictEqual(syms[0].name, 'M1');

assert.ok(syms[0].children);
assert.deepStrictEqual(syms[0]?.children[0]?.kind, lc.SymbolKind.Constant);
assert.deepStrictEqual(syms[0]?.children[0].name, 'SOME_CONST');
assert.deepStrictEqual(syms[0]?.children[1]?.kind, lc.SymbolKind.Struct);
assert.deepStrictEqual(syms[0]?.children[1].name, 'SomeOtherStruct');
assert.ok(syms[0].children[1].children);
assert.deepStrictEqual(syms[0]?.children[1]?.children[0]?.kind, lc.SymbolKind.Field);
assert.deepStrictEqual(syms[0]?.children[1]?.children[0]?.name, 'some_field');
assert.deepStrictEqual(syms[0]?.children[1].name, 'SomeOtherStruct');
assert.deepStrictEqual(syms[0]?.children[2]?.kind, lc.SymbolKind.Function);
assert.deepStrictEqual(syms[0]?.children[2].name, 'some_other_struct');
assert.deepStrictEqual(syms[0]?.children[3]?.kind, lc.SymbolKind.Function);
assert.deepStrictEqual(syms[0]?.children[3].name, 'this_is_a_test');
assert.deepStrictEqual(syms[0]?.children[3]?.detail, '["test", "expected_failure"]');
});
});
23 changes: 21 additions & 2 deletions language/move-analyzer/editors/code/tests/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*/

import * as path from 'path';
import { runTests } from '@vscode/test-electron';
import * as cp from 'child_process';
import { runTests, downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } from '@vscode/test-electron';

/**
* Launches a VS Code instance to run tests.
Expand All @@ -28,8 +29,26 @@ async function main(): Promise<void> {
// program that is considered to be the "test suite" for the extension.
const extensionTestsPath = path.resolve(__dirname, 'index.js');

// The workspace
const testWorkspacePath = path.resolve(__dirname, './lsp-demo/lsp-demo.code-workspace');

// Install vscode and depends extension
const vscodeVersion = '1.64.0';
const vscodeExecutablePath = await downloadAndUnzipVSCode(vscodeVersion);
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
const newCli = cli ?? 'code';
cp.spawnSync(newCli, [...args, '--install-extension', 'damirka.move-syntax', '--force'], {
encoding: 'utf-8',
stdio: 'inherit',
});

// Download VS Code, unzip it, and run the "test suite" program.
await runTests({ extensionDevelopmentPath, extensionTestsPath });
await runTests({
vscodeExecutablePath: vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspacePath],
});
} catch (_err: unknown) {
console.error('Failed to run tests');
process.exit(1);
Expand Down

This file was deleted.

Loading