Skip to content

editor/code: Allow to apply static analysis for codes opened in webview #15256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 change: 1 addition & 0 deletions editors/code/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
// use 100 because it's Rustfmt's default
// https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#max_width
printWidth: 100,
tabWidth: 4,
};
1 change: 1 addition & 0 deletions editors/code/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
!node_modules/d3-graphviz/build/d3-graphviz.min.js
!node_modules/d3/dist/d3.min.js
!out/main.js
!out/webview/
!package-lock.json
!package.json
!ra_syntax_tree.tmGrammar.json
Expand Down
18 changes: 9 additions & 9 deletions editors/code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ It is recommended over and replaces `rust-lang.rust`.

## Features

- [code completion] with [imports insertion]
- go to [definition], [implementation], [type definition]
- [find all references], [workspace symbol search], [symbol renaming]
- [types and documentation on hover]
- [inlay hints] for types and parameter names
- [semantic syntax highlighting]
- a lot of [assists (code actions)]
- apply suggestions from errors
- ... and many more, check out the [manual] to see them all
- [code completion] with [imports insertion]
- go to [definition], [implementation], [type definition]
- [find all references], [workspace symbol search], [symbol renaming]
- [types and documentation on hover]
- [inlay hints] for types and parameter names
- [semantic syntax highlighting]
- a lot of [assists (code actions)]
- apply suggestions from errors
- ... and many more, check out the [manual] to see them all

[code completion]: https://rust-analyzer.github.io/manual.html#magic-completions
[imports insertion]: https://rust-analyzer.github.io/manual.html#completion-with-autoimport
Expand Down
94 changes: 94 additions & 0 deletions editors/code/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as path from "node:path";
import { parseArgs } from "node:util";
import * as esbuild from "esbuild";

function parseCliOptions() {
const { values } = parseArgs({
options: {
minify: {
type: "boolean",
default: false,
},
sourcemap: {
type: "boolean",
default: false,
},
watch: {
type: "boolean",
default: false,
},
},
strict: true,
});
return {
shouldMinify: !!values.minify,
shouldEmitSourceMap: !!values.sourcemap,
isWatchMode: !!values.watch,
};
}

const { shouldMinify, shouldEmitSourceMap, isWatchMode } = parseCliOptions();

const OUT_DIR = "./out";
const OUT_WEBVIEW_DIR = path.resolve(OUT_DIR, "webview");

/** @type {esbuild.BuildOptions} */
const BASE_OPTIONS = {
minify: shouldMinify,
sourcemap: shouldEmitSourceMap ? "external" : false,
bundle: true,
};

function createBuildOption(entryPoints) {
/** @type {esbuild.BuildOptions} */
const options = {
...BASE_OPTIONS,
entryPoints,
external: ["vscode"],
format: "cjs",
platform: "node",
target: "node16",
outdir: OUT_DIR,
};
return options;
}

function createBuildOptionForWebView(entryPoints) {
/** @type {esbuild.BuildOptions} */
const options = {
...BASE_OPTIONS,
entryPoints,
format: "esm",
platform: "browser",
// VSCode v1.78 (Electron 22) uses Chromium 108.
Copy link
Member

Choose a reason for hiding this comment

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

We're back on 1.75 since #15333.

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'll update to:

- // VSCode v1.78 (Electron 22) uses Chromium 108.
+ // VSCode v1.75 (Electron 19) uses Chromium 102.

// https://code.visualstudio.com/updates/v1_78
target: "chrome108",
outdir: OUT_WEBVIEW_DIR,
};
return options;
}

async function bundleSource(options) {
if (!isWatchMode) {
return esbuild.build(options);
}

const ctx = await esbuild.context(options);
return ctx.watch();
}

await Promise.all([
bundleSource(createBuildOption(["src/main.ts"])),
bundleSource(
createBuildOptionForWebView([
"src/webview/show_crate_graph.ts",
"src/webview/show_crate_graph.css",
]),
),
bundleSource(
createBuildOptionForWebView([
"src/webview/view_memory_layout.ts",
"src/webview/view_memory_layout.css",
]),
),
]);
2 changes: 1 addition & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"vscode:prepublish": "npm run build-base -- --minify",
"package": "vsce package -o rust-analyzer.vsix",
"build-base": "esbuild ./src/main.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --target=node16",
"build-base": "node ./build.mjs",
"build": "npm run build-base -- --sourcemap",
"watch": "npm run build-base -- --sourcemap --watch",
"format": "prettier --write .",
Expand Down
Loading