Support DidChangeWorkspaceFolders capability
This commit is contained in:
parent
7f1234492e
commit
c7010eda1b
6 changed files with 66 additions and 26 deletions
|
|
@ -14,7 +14,7 @@ use ide_db::base_db::{SourceDatabaseExt, VfsPath};
|
|||
use itertools::Itertools;
|
||||
use lsp_server::{Connection, Notification, Request};
|
||||
use lsp_types::notification::Notification as _;
|
||||
use vfs::{ChangeKind, FileId};
|
||||
use vfs::{AbsPathBuf, ChangeKind, FileId};
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
|
|
@ -933,6 +933,30 @@ impl GlobalState {
|
|||
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_types::notification::DidChangeWorkspaceFolders>(|this, params| {
|
||||
let config = Arc::make_mut(&mut this.config);
|
||||
|
||||
for workspace in params.event.removed {
|
||||
let Ok(path) = workspace.uri.to_file_path() else { continue };
|
||||
let Ok(path) = AbsPathBuf::try_from(path) else { continue };
|
||||
let Some(position) = config.workspace_roots.iter().position(|it| it == &path) else { continue };
|
||||
config.workspace_roots.remove(position);
|
||||
}
|
||||
|
||||
let added = params
|
||||
.event
|
||||
.added
|
||||
.into_iter()
|
||||
.filter_map(|it| it.uri.to_file_path().ok())
|
||||
.filter_map(|it| AbsPathBuf::try_from(it).ok());
|
||||
config.workspace_roots.extend(added);
|
||||
if !config.has_linked_projects() && config.detached_files().is_empty() {
|
||||
config.rediscover_workspaces();
|
||||
this.fetch_workspaces_queue.request_op("client workspaces changed".to_string())
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_types::notification::DidChangeWatchedFiles>(|this, params| {
|
||||
for change in params.changes {
|
||||
if let Ok(path) = from_proto::abs_path(&change.uri) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue