Skip to content

RIIR vscode extension #16515

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ jobs:
if: matrix.os == 'ubuntu-latest' && needs.changes.outputs.typescript == 'true'
run: sudo apt-get install -y xvfb

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- run: npm ci
working-directory: ./editors/code
if: needs.changes.outputs.typescript == 'true'
Expand Down
67 changes: 67 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = ["xtask/", "lib/*", "crates/*"]
members = ["xtask/", "lib/*", "crates/*", "editors/code/wasm"]
exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]

resolver = "2"

[workspace.package]
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
&'a self,
ctor: &'a rustc_pattern_analysis::constructor::Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = Self::Ty> + ExactSizeIterator + Captures<'a> {
) -> impl ExactSizeIterator<Item = Self::Ty> + Captures<'a> {
let single = |ty| smallvec![ty];
let tys: SmallVec<[_; 2]> = match ctor {
Struct | Variant(_) | UnionField => match ty.kind(Interner) {
Expand Down
2 changes: 1 addition & 1 deletion editors/code/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},
plugins: ["@typescript-eslint"],
rules: {
camelcase: ["error"],
camelcase: ["off"], // This lint causes more trouble than good when mixing Rust and TS
eqeqeq: ["error", "always", { null: "ignore" }],
curly: ["error", "multi-line"],
"no-console": ["error", { allow: ["warn", "error"] }],
Expand Down
1 change: 1 addition & 0 deletions editors/code/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.vscode-test
out
wasm/pkg
6 changes: 4 additions & 2 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
"enabledApiProposals": [],
"scripts": {
"vscode:prepublish": "npm run build-base -- --minify",
"package": "vsce package -o rust-analyzer.vsix",
"package": "vsce package -o rust-analyzer.vsix && npm run patch-vsix",
"patch-vsix": "bash -c 'mkdir -p extension/out && cp wasm/pkg/* extension/out/ && 7z a rust-analyzer.vsix extension/out/* && rm -r extension'",
"build-base": "esbuild ./src/main.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --target=node16",
"build-wasm": "cd wasm && wasm-pack build -t nodejs",
"build": "npm run build-base -- --sourcemap",
"watch": "npm run build-base -- --sourcemap --watch",
"format": "prettier --write .",
"format:check": "prettier --check .",
"lint": "eslint -c .eslintrc.js --ext ts ./src ./tests",
"lint:fix": "npm run lint -- --fix",
"typecheck": "tsc",
"typecheck": "npm run build-wasm && tsc",
"pretest": "npm run typecheck && npm run build",
"test": "node ./out/tests/runTests.js"
},
Expand Down
31 changes: 7 additions & 24 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as diagnostics from "./diagnostics";
import { activateTaskProvider } from "./tasks";
import { setContextValue } from "./util";
import type { JsonProject } from "./rust_project";
import { check_conflicting_extensions } from "../wasm/pkg/vscode_ra_wasm";

const RUST_PROJECT_CONTEXT_NAME = "inRustProject";

Expand All @@ -22,10 +23,15 @@ export async function deactivate() {
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
}

// @ts-ignore
globalThis.vscode_window = vscode.window;
// @ts-ignore
globalThis.vscode_extensions = vscode.extensions;

export async function activate(
context: vscode.ExtensionContext,
): Promise<RustAnalyzerExtensionApi> {
checkConflictingExtensions();
check_conflicting_extensions();

const ctx = new Ctx(context, createCommands(), fetchWorkspace());
// VS Code doesn't show a notification when an extension fails to activate
Expand Down Expand Up @@ -191,26 +197,3 @@ function createCommands(): Record<string, CommandFactory> {
revealDependency: { enabled: commands.revealDependency },
};
}

function checkConflictingExtensions() {
if (vscode.extensions.getExtension("rust-lang.rust")) {
vscode.window
.showWarningMessage(
`You have both the rust-analyzer (rust-lang.rust-analyzer) and Rust (rust-lang.rust) ` +
"plugins enabled. These are known to conflict and cause various functions of " +
"both plugins to not work correctly. You should disable one of them.",
"Got it",
)
.then(() => {}, console.error);
}

if (vscode.extensions.getExtension("panicbit.cargo")) {
vscode.window
.showWarningMessage(
`You have both the rust-analyzer (rust-lang.rust-analyzer) and Cargo (panicbit.cargo) plugins enabled, ` +
'you can disable it or set {"cargo.automaticCheck": false} in settings.json to avoid invoking cargo twice',
"Got it",
)
.then(() => {}, console.error);
}
}
13 changes: 13 additions & 0 deletions editors/code/wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "vscode_ra_wasm"
version = "0.1.0"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2.74"
23 changes: 23 additions & 0 deletions editors/code/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use wasm_bindgen::prelude::*;

pub mod vscode;

#[wasm_bindgen]
pub fn check_conflicting_extensions() {
if vscode::extensions::getExtension("rust-lang.rust").is_truthy() {
vscode::window::showWarningMessage(
"You have both the rust-analyzer (rust-lang.rust-analyzer) and Rust (rust-lang.rust) \
plugins enabled. These are known to conflict and cause various functions of \
both plugins to not work correctly. You should disable one of them.",
"Got it",
);
}

if vscode::extensions::getExtension("panicbit.cargo").is_truthy() {
vscode::window::showWarningMessage(
"You have both the rust-analyzer (rust-lang.rust-analyzer) and Cargo (panicbit.cargo) plugins enabled, \
you can disable it or set {'cargo.automaticCheck': false} in settings.json to avoid invoking cargo twice",
"Got it",
);
}
}
19 changes: 19 additions & 0 deletions editors/code/wasm/src/vscode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pub mod window {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = vscode_window)]
pub fn showWarningMessage(message: &str, button: &str);
}
}

pub mod extensions {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = vscode_extensions)]
pub fn getExtension(s: &str) -> JsValue;
}
}