Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: async compile in lsp #922

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Peefy marked this conversation as resolved.
Show resolved Hide resolved
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
Loading