mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
migrate analysis and server to 2018
This commit is contained in:
parent
2dd6858d03
commit
bb298158eb
21 changed files with 42 additions and 36 deletions
|
@ -1,4 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
|
edition = "2018"
|
||||||
name = "ra_analysis"
|
name = "ra_analysis"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use salsa;
|
use salsa;
|
||||||
use {FileId, imp::FileResolverImp};
|
use crate::{FileId, imp::FileResolverImp};
|
||||||
use super::{State, Query, QueryCtx};
|
use super::{State, Query, QueryCtx};
|
||||||
|
|
||||||
pub(super) type Data = Arc<Any + Send + Sync + 'static>;
|
pub(super) type Data = Arc<Any + Send + Sync + 'static>;
|
||||||
|
@ -51,7 +51,7 @@ pub(crate) trait EvalQuery {
|
||||||
type Output;
|
type Output;
|
||||||
fn query_type(&self) -> salsa::QueryTypeId;
|
fn query_type(&self) -> salsa::QueryTypeId;
|
||||||
fn f(&self) -> salsa::QueryFn<State, Data>;
|
fn f(&self) -> salsa::QueryFn<State, Data>;
|
||||||
fn get(&self, &QueryCtx, Self::Params) -> Arc<Self::Output>;
|
fn get(&self, ctx: &QueryCtx, params: Self::Params) -> Arc<Self::Output>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R> EvalQuery for Query<T, R>
|
impl<T, R> EvalQuery for Query<T, R>
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use im;
|
use im;
|
||||||
use salsa;
|
use salsa;
|
||||||
use {FileId, imp::FileResolverImp};
|
use crate::{FileId, imp::FileResolverImp};
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub(crate) struct State {
|
pub(crate) struct State {
|
||||||
|
@ -75,8 +75,8 @@ pub(crate) fn file_set(ctx: QueryCtx) -> Arc<(Vec<FileId>, FileResolverImp)> {
|
||||||
impl QueryRegistry {
|
impl QueryRegistry {
|
||||||
fn new() -> QueryRegistry {
|
fn new() -> QueryRegistry {
|
||||||
let mut reg = QueryRegistry { imp: imp::QueryRegistry::new() };
|
let mut reg = QueryRegistry { imp: imp::QueryRegistry::new() };
|
||||||
::queries::register_queries(&mut reg);
|
crate::queries::register_queries(&mut reg);
|
||||||
::module_map::register_queries(&mut reg);
|
crate::module_map::register_queries(&mut reg);
|
||||||
reg
|
reg
|
||||||
}
|
}
|
||||||
pub(crate) fn add<Q: imp::EvalQuery>(&mut self, q: Q, name: &'static str) {
|
pub(crate) fn add<Q: imp::EvalQuery>(&mut self, q: Q, name: &'static str) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use ra_syntax::{
|
||||||
ast::{self, NameOwner, AstNode},
|
ast::{self, NameOwner, AstNode},
|
||||||
text_utils::is_subrange
|
text_utils::is_subrange
|
||||||
};
|
};
|
||||||
use {
|
use crate::{
|
||||||
FileId,
|
FileId,
|
||||||
imp::FileResolverImp,
|
imp::FileResolverImp,
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ use ra_syntax::{
|
||||||
ast::{self, NameOwner, ArgListOwner, Expr},
|
ast::{self, NameOwner, ArgListOwner, Expr},
|
||||||
};
|
};
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit,
|
FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit,
|
||||||
JobToken, CrateGraph, CrateId,
|
JobToken, CrateGraph, CrateId,
|
||||||
roots::{SourceRoot, ReadonlySourceRoot, WritableSourceRoot},
|
roots::{SourceRoot, ReadonlySourceRoot, WritableSourceRoot},
|
||||||
|
|
|
@ -29,16 +29,18 @@ use std::{
|
||||||
|
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::{RelativePath, RelativePathBuf};
|
||||||
use ra_syntax::{File, TextRange, TextUnit, AtomEdit};
|
use ra_syntax::{File, TextRange, TextUnit, AtomEdit};
|
||||||
use imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
|
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use crate::imp::{AnalysisImpl, AnalysisHostImpl, FileResolverImp};
|
||||||
|
|
||||||
pub use ra_editor::{
|
pub use ra_editor::{
|
||||||
StructureNode, LineIndex, FileSymbol,
|
StructureNode, LineIndex, FileSymbol,
|
||||||
Runnable, RunnableKind, HighlightedRange, CompletionItem,
|
Runnable, RunnableKind, HighlightedRange, CompletionItem,
|
||||||
Fold, FoldKind
|
Fold, FoldKind
|
||||||
};
|
};
|
||||||
pub use job::{JobToken, JobHandle};
|
pub use crate::{
|
||||||
pub use descriptors::FnDescriptor;
|
job::{JobToken, JobHandle},
|
||||||
|
descriptors::FnDescriptor,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(pub u32);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use {
|
use crate::{
|
||||||
FileId,
|
FileId,
|
||||||
db::{
|
db::{
|
||||||
Query, QueryRegistry, QueryCtx,
|
Query, QueryRegistry, QueryCtx,
|
||||||
|
@ -38,7 +38,7 @@ mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use im;
|
use im;
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::{RelativePath, RelativePathBuf};
|
||||||
use {
|
use crate::{
|
||||||
db::{Db},
|
db::{Db},
|
||||||
imp::FileResolverImp,
|
imp::FileResolverImp,
|
||||||
FileId, FileResolver,
|
FileId, FileResolver,
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use ra_syntax::File;
|
use ra_syntax::File;
|
||||||
use ra_editor::LineIndex;
|
use ra_editor::LineIndex;
|
||||||
use {
|
use crate::{
|
||||||
FileId,
|
FileId,
|
||||||
db::{Query, QueryCtx, QueryRegistry},
|
db::{Query, QueryCtx, QueryRegistry},
|
||||||
symbol_index::SymbolIndex,
|
symbol_index::SymbolIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use db::{file_text, file_set};
|
pub(crate) use crate::db::{file_text, file_set};
|
||||||
|
|
||||||
pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
||||||
(&*ctx.get(FILE_SYNTAX, file_id)).clone()
|
(&*ctx.get(FILE_SYNTAX, file_id)).clone()
|
||||||
|
|
|
@ -9,7 +9,7 @@ use rustc_hash::FxHashMap;
|
||||||
use ra_editor::LineIndex;
|
use ra_editor::LineIndex;
|
||||||
use ra_syntax::File;
|
use ra_syntax::File;
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
FileId,
|
FileId,
|
||||||
imp::FileResolverImp,
|
imp::FileResolverImp,
|
||||||
symbol_index::SymbolIndex,
|
symbol_index::SymbolIndex,
|
||||||
|
@ -62,23 +62,23 @@ impl WritableSourceRoot {
|
||||||
|
|
||||||
impl SourceRoot for WritableSourceRoot {
|
impl SourceRoot for WritableSourceRoot {
|
||||||
fn module_tree(&self) -> Arc<ModuleTreeDescriptor> {
|
fn module_tree(&self) -> Arc<ModuleTreeDescriptor> {
|
||||||
self.db.make_query(::module_map::module_tree)
|
self.db.make_query(crate::module_map::module_tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains(&self, file_id: FileId) -> bool {
|
fn contains(&self, file_id: FileId) -> bool {
|
||||||
self.db.state().file_map.contains_key(&file_id)
|
self.db.state().file_map.contains_key(&file_id)
|
||||||
}
|
}
|
||||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
|
fn lines(&self, file_id: FileId) -> Arc<LineIndex> {
|
||||||
self.db.make_query(|ctx| ::queries::file_lines(ctx, file_id))
|
self.db.make_query(|ctx| crate::queries::file_lines(ctx, file_id))
|
||||||
}
|
}
|
||||||
fn syntax(&self, file_id: FileId) -> File {
|
fn syntax(&self, file_id: FileId) -> File {
|
||||||
self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id))
|
self.db.make_query(|ctx| crate::queries::file_syntax(ctx, file_id))
|
||||||
}
|
}
|
||||||
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
||||||
self.db.make_query(|ctx| {
|
self.db.make_query(|ctx| {
|
||||||
let file_set = ::queries::file_set(ctx);
|
let file_set = crate::queries::file_set(ctx);
|
||||||
let syms = file_set.0.iter()
|
let syms = file_set.0.iter()
|
||||||
.map(|file_id| ::queries::file_symbols(ctx, *file_id));
|
.map(|file_id| crate::queries::file_symbols(ctx, *file_id));
|
||||||
acc.extend(syms);
|
acc.extend(syms);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use ra_syntax::{
|
||||||
};
|
};
|
||||||
use fst::{self, Streamer};
|
use fst::{self, Streamer};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use {Query, FileId, JobToken};
|
use crate::{Query, FileId, JobToken};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct SymbolIndex {
|
pub(crate) struct SymbolIndex {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
|
edition = "2018"
|
||||||
name = "ra_lsp_server"
|
name = "ra_lsp_server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
|
@ -7,7 +7,7 @@ use ra_editor::{LineIndex, LineCol, Edit, AtomEdit};
|
||||||
use ra_syntax::{SyntaxKind, TextUnit, TextRange};
|
use ra_syntax::{SyntaxKind, TextUnit, TextRange};
|
||||||
use ra_analysis::{FileId, SourceChange, SourceFileEdit, FileSystemEdit};
|
use ra_analysis::{FileId, SourceChange, SourceFileEdit, FileSystemEdit};
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
Result,
|
Result,
|
||||||
server_world::ServerWorld,
|
server_world::ServerWorld,
|
||||||
req,
|
req,
|
||||||
|
@ -299,7 +299,7 @@ pub fn to_location(
|
||||||
Ok(loc)
|
Ok(loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MapConvWith<'a>: Sized {
|
pub trait MapConvWith<'a>: Sized + 'a {
|
||||||
type Ctx;
|
type Ctx;
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ pub trait MapConvWith<'a>: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I> MapConvWith<'a> for I
|
impl<'a, I> MapConvWith<'a> for I
|
||||||
where I: Iterator,
|
where I: Iterator + 'a,
|
||||||
I::Item: ConvWith
|
I::Item: ConvWith
|
||||||
{
|
{
|
||||||
type Ctx = <I::Item as ConvWith>::Ctx;
|
type Ctx = <I::Item as ConvWith>::Ctx;
|
||||||
|
|
|
@ -34,5 +34,7 @@ mod project_model;
|
||||||
pub mod thread_watcher;
|
pub mod thread_watcher;
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
||||||
pub use caps::server_capabilities;
|
pub use crate::{
|
||||||
pub use main_loop::main_loop;
|
main_loop::main_loop,
|
||||||
|
caps::server_capabilities,
|
||||||
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@ use ra_syntax::{
|
||||||
text_utils::contains_offset_nonstrict
|
text_utils::contains_offset_nonstrict
|
||||||
};
|
};
|
||||||
|
|
||||||
use ::{
|
use crate::{
|
||||||
req::{self, Decoration}, Result,
|
req::{self, Decoration}, Result,
|
||||||
conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location},
|
conv::{Conv, ConvWith, TryConvWith, MapConvWith, to_location},
|
||||||
server_world::ServerWorld,
|
server_world::ServerWorld,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use gen_lsp_server::{
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
req,
|
req,
|
||||||
Result,
|
Result,
|
||||||
vfs::{self, FileEvent},
|
vfs::{self, FileEvent},
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use cargo_metadata::{metadata_run, CargoOpt};
|
use cargo_metadata::{metadata_run, CargoOpt};
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
Result,
|
Result,
|
||||||
thread_watcher::{Worker, ThreadWatcher},
|
thread_watcher::{Worker, ThreadWatcher},
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
|
||||||
use languageserver_types::Url;
|
use languageserver_types::Url;
|
||||||
use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver};
|
use ra_analysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver};
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
Result,
|
Result,
|
||||||
path_map::{PathMap, Root},
|
path_map::{PathMap, Root},
|
||||||
vfs::{FileEvent, FileEventKind},
|
vfs::{FileEvent, FileEventKind},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use crossbeam_channel::{bounded, unbounded, Sender, Receiver};
|
use crossbeam_channel::{bounded, unbounded, Sender, Receiver};
|
||||||
use drop_bomb::DropBomb;
|
use drop_bomb::DropBomb;
|
||||||
use Result;
|
use crate::Result;
|
||||||
|
|
||||||
pub struct Worker<I, O> {
|
pub struct Worker<I, O> {
|
||||||
pub inp: Sender<I>,
|
pub inp: Sender<I>,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use {
|
use crate::{
|
||||||
thread_watcher::{Worker, ThreadWatcher},
|
thread_watcher::{Worker, ThreadWatcher},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ mod support;
|
||||||
|
|
||||||
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
||||||
|
|
||||||
use support::project;
|
use crate::support::project;
|
||||||
|
|
||||||
|
|
||||||
const LOG: &'static str = "";
|
const LOG: &'static str = "";
|
||||||
|
|
|
@ -25,7 +25,7 @@ use ra_lsp_server::{main_loop, req, thread_watcher::{ThreadWatcher, Worker}};
|
||||||
|
|
||||||
pub fn project(fixture: &str) -> Server {
|
pub fn project(fixture: &str) -> Server {
|
||||||
static INIT: Once = Once::new();
|
static INIT: Once = Once::new();
|
||||||
INIT.call_once(|| Logger::with_env_or_str(::LOG).start().unwrap());
|
INIT.call_once(|| Logger::with_env_or_str(crate::LOG).start().unwrap());
|
||||||
|
|
||||||
let tmp_dir = TempDir::new("test-project")
|
let tmp_dir = TempDir::new("test-project")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue