From 80a42a0628f7655c3299fbf4c5a15e31990b35d3 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 23 Apr 2020 23:29:40 +0200 Subject: [PATCH 1/2] Add Launch configuration for release build --- .vscode/launch.json | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ca70fb2098e..3f74d75666d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "configurations": [ { // Used for testing the extension with the installed LSP server. - "name": "Run Extension", + "name": "Run Installed Extension", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", @@ -30,7 +30,7 @@ }, { // Used for testing the extension with a local build of the LSP server (in `target/debug`). - "name": "Run Extension (Dev Server)", + "name": "Run Extension (Debug Build)", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", @@ -49,6 +49,27 @@ "__RA_LSP_SERVER_DEBUG": "${workspaceFolder}/target/debug/rust-analyzer" } }, + { + // Used for testing the extension with a local build of the LSP server (in `target/release`). + "name": "Run Extension (Release Build)", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--disable-extensions", + "--extensionDevelopmentPath=${workspaceFolder}/editors/code" + ], + "outFiles": [ + "${workspaceFolder}/editors/code/out/**/*.js" + ], + "preLaunchTask": "Build Extension", + "skipFiles": [ + "/**/*.js" + ], + "env": { + "__RA_LSP_SERVER_DEBUG": "${workspaceFolder}/target/release/rust-analyzer" + } + }, { // Used to attach LLDB to a running LSP server. // NOTE: Might require root permissions. For this run: From 5cc9546ca0d5ac0d733e5ea39cbfceb5984482e0 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 23 Apr 2020 23:10:14 +0200 Subject: [PATCH 2/2] Record definitions in `extern` blocks --- crates/ra_hir_def/src/nameres/raw.rs | 32 ++++++++++++++++++++++++-- crates/ra_hir_def/src/nameres/tests.rs | 9 +++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index afd538e4acb..39b011ad724 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -266,8 +266,8 @@ fn add_item(&mut self, current_module: Option>, item: ast::Modul self.add_macro(current_module, it); return; } - ast::ModuleItem::ExternBlock(_) => { - // FIXME: add extern block + ast::ModuleItem::ExternBlock(it) => { + self.add_extern_block(current_module, it); return; } }; @@ -278,6 +278,34 @@ fn add_item(&mut self, current_module: Option>, item: ast::Modul } } + fn add_extern_block( + &mut self, + current_module: Option>, + block: ast::ExternBlock, + ) { + if let Some(items) = block.extern_item_list() { + for item in items.extern_items() { + let attrs = self.parse_attrs(&item); + let visibility = + RawVisibility::from_ast_with_hygiene(item.visibility(), &self.hygiene); + let (kind, name) = match item { + ast::ExternItem::FnDef(it) => { + (DefKind::Function(self.source_ast_id_map.ast_id(&it)), it.name()) + } + ast::ExternItem::StaticDef(it) => { + (DefKind::Static(self.source_ast_id_map.ast_id(&it)), it.name()) + } + }; + + if let Some(name) = name { + let name = name.as_name(); + let def = self.raw_items.defs.alloc(DefData { name, kind, visibility }); + self.push_item(current_module, attrs, RawItemKind::Def(def)); + } + } + } + } + fn add_module(&mut self, current_module: Option>, module: ast::Module) { let name = match module.name() { Some(it) => it.as_name(), diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 949ca7595fe..83120fa365d 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -25,7 +25,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc { #[test] fn crate_def_map_smoke_test() { let map = def_map( - " + r" //- /lib.rs mod foo; struct S; @@ -45,6 +45,11 @@ union U { } enum E { V } + + extern { + static EXT: u8; + fn ext(); + } ", ); assert_snapshot!(map, @r###" @@ -61,7 +66,9 @@ enum E { V } ⋮crate::foo::bar ⋮Baz: t v ⋮E: t + ⋮EXT: v ⋮U: t v + ⋮ext: v "###) }