4111: Record definitions in `extern` blocks r=jonas-schievink a=jonas-schievink

Enables completion of extern functions and statics.

Closes https://github.com/rust-analyzer/rust-analyzer/issues/3711

4112: Add Launch configuration for release build r=matklad a=jonas-schievink

The debug build takes very long until I can test anything useful, with the release build it's much quicker. Add another Run configuration for it.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2020-04-23 21:37:06 +00:00 committed by GitHub
commit 01f1f10fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 5 deletions

25
.vscode/launch.json vendored
View File

@ -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": [
"<node_internals>/**/*.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:

View File

@ -266,8 +266,8 @@ fn add_item(&mut self, current_module: Option<Idx<ModuleData>>, 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<Idx<ModuleData>>, item: ast::Modul
}
}
fn add_extern_block(
&mut self,
current_module: Option<Idx<ModuleData>>,
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<Idx<ModuleData>>, module: ast::Module) {
let name = match module.name() {
Some(it) => it.as_name(),

View File

@ -25,7 +25,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
#[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
"###)
}