Refactor primary IDE API

This introduces the new type -- Semantics.
Semantics maps SyntaxNodes to various semantic info, such as type,
name resolution or macro expansions.

To do so, Semantics maintains a HashMap which maps every node it saw
to the file from which the node originated. This is enough to get all
the necessary hir bits just from syntax.
This commit is contained in:
Aleksey Kladov 2020-02-18 18:35:10 +01:00
parent 04deae3dba
commit c3a4c4429d
49 changed files with 1026 additions and 978 deletions

View file

@ -2,7 +2,10 @@
use std::cell::RefCell;
use hir::diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink};
use hir::{
diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink},
Semantics,
};
use itertools::Itertools;
use ra_db::{RelativePath, SourceDatabase, SourceDatabaseExt};
use ra_ide_db::RootDatabase;
@ -24,7 +27,7 @@ pub enum Severity {
pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> {
let _p = profile("diagnostics");
let mut sb = hir::SourceBinder::new(db);
let sema = Semantics::new(db);
let parse = db.parse(file_id);
let mut res = Vec::new();
@ -110,7 +113,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
fix: Some(fix),
})
});
if let Some(m) = sb.to_module_def(file_id) {
if let Some(m) = sema.to_module_def(file_id) {
m.diagnostics(db, &mut sink);
};
drop(sink);