Skip to content

Commit

Permalink
feat: async compile in lsp (#922)
Browse files Browse the repository at this point in the history
* feat: asymc compile in lsp. 1 support async compile when vfs changes(open file and ChangeTextDocument). 2. remove scope in lsp db

Signed-off-by: he1pa <[email protected]>

* fix: fix unwrap() in request.rs and completion.rs

Signed-off-by: he1pa <[email protected]>

* test: fix ut

Signed-off-by: he1pa <[email protected]>

---------

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Nov 28, 2023
1 parent 85d93a8 commit 5ab79bb
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 310 deletions.
11 changes: 3 additions & 8 deletions kclvm/tools/src/LSP/src/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use crate::db::AnalysisDatabase;
use parking_lot::RwLock;
use ra_ap_vfs::FileId;
use std::collections::HashMap;
use std::{collections::HashMap, sync::Arc};

#[derive(Default)]
pub struct Analysis {
pub db: HashMap<FileId, AnalysisDatabase>,
}

impl Analysis {
pub fn set_db(&mut self, id: FileId, db: AnalysisDatabase) {
self.db.insert(id, db);
}
pub db: Arc<RwLock<HashMap<FileId, AnalysisDatabase>>>,
}
147 changes: 70 additions & 77 deletions kclvm/tools/src/LSP/src/completion.rs

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions kclvm/tools/src/LSP/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use indexmap::IndexSet;
use kclvm_ast::ast::Program;
use kclvm_error::Diagnostic;
use kclvm_sema::{core::global_state::GlobalState, resolver::scope::ProgramScope};
use kclvm_sema::core::global_state::GlobalState;

/// Holds the result of the compile
#[derive(Default, Clone)]
pub struct AnalysisDatabase {
pub prog: Program,
pub scope: ProgramScope,
pub diags: IndexSet<Diagnostic>,
pub gs: GlobalState,
}
8 changes: 2 additions & 6 deletions kclvm/tools/src/LSP/src/find_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use kclvm_ast::ast::Program;
use kclvm_error::Position as KCLPos;
use kclvm_parser::KCLModuleCache;
use kclvm_sema::core::global_state::GlobalState;
use kclvm_sema::resolver::scope::ProgramScope;
use lsp_types::{Location, Url};
use parking_lot::RwLock;
use ra_ap_vfs::Vfs;
Expand All @@ -18,7 +17,6 @@ pub(crate) fn find_refs<F: Fn(String) -> Result<(), anyhow::Error>>(
_program: &Program,
kcl_pos: &KCLPos,
include_declaration: bool,
_prog_scope: &ProgramScope,
word_index_map: Arc<RwLock<HashMap<Url, HashMap<String, Vec<Location>>>>>,
vfs: Option<Arc<RwLock<Vfs>>>,
logger: F,
Expand Down Expand Up @@ -86,15 +84,13 @@ pub(crate) fn find_refs_from_def<F: Fn(String) -> Result<(), anyhow::Error>>(
},
vfs.clone(),
) {
Ok((prog, scope, _, gs)) => {
Ok((prog, _, _, gs)) => {
let ref_pos = kcl_pos(&file_path, ref_loc.range.start);
if *ref_loc == def_loc && !include_declaration {
return false;
}
// find def from the ref_pos
if let Some(real_def) =
goto_definition_with_gs(&prog, &ref_pos, &scope, &gs)
{
if let Some(real_def) = goto_definition_with_gs(&prog, &ref_pos, &gs) {
match real_def {
lsp_types::GotoDefinitionResponse::Scalar(real_def_loc) => {
real_def_loc == def_loc
Expand Down
Loading

0 comments on commit 5ab79bb

Please sign in to comment.