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

refactor(language_server): use papaya instead of dashmap #9220

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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/oxc_language_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ oxc_semantic = { workspace = true }
oxc_span = { workspace = true }

cow-utils = { workspace = true }
dashmap = { workspace = true }
env_logger = { workspace = true, features = ["humantime"] }
futures = { workspace = true }
globset = { workspace = true }
ignore = { workspace = true, features = ["simd-accel"] }
log = { workspace = true }
papaya = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_language_server/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl WorkspaceCommand for FixAllCommand {
let url = url.unwrap();

let mut edits = vec![];
if let Some(value) = backend.diagnostics_report_map.get(&url.to_string()) {
for report in value.iter() {
if let Some(value) = backend.diagnostics_report_map.pin_owned().get(&url.to_string()) {
for report in value {
if let Some(fixed) = &report.fixed_content {
edits.push(TextEdit { range: fixed.range, new_text: fixed.code.clone() });
}
Expand Down
26 changes: 13 additions & 13 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{fmt::Debug, path::PathBuf, str::FromStr};

use commands::LSP_COMMANDS;
use dashmap::DashMap;
use futures::future::join_all;
use globset::Glob;
use ignore::gitignore::Gitignore;
Expand Down Expand Up @@ -32,13 +31,13 @@ mod capabilities;
mod commands;
mod linter;

type FxDashMap<K, V> = DashMap<K, V, FxBuildHasher>;
type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;

struct Backend {
client: Client,
root_uri: OnceCell<Option<Url>>,
server_linter: RwLock<ServerLinter>,
diagnostics_report_map: FxDashMap<String, Vec<DiagnosticReport>>,
diagnostics_report_map: ConcurrentHashMap<String, Vec<DiagnosticReport>>,
options: Mutex<Options>,
gitignore_glob: Mutex<Vec<Gitignore>>,
}
Expand Down Expand Up @@ -153,13 +152,14 @@ impl LanguageServer for Backend {
{
debug!("lint level change detected {:?}", &changed_options.get_lint_level());
// clear all exists diagnostics when linter is disabled
let opened_files = self.diagnostics_report_map.iter().map(|k| k.key().to_string());
let cleared_diagnostics = opened_files
.into_iter()
let cleared_diagnostics = self
.diagnostics_report_map
.pin()
.keys()
.map(|uri| {
(
// should convert successfully, case the key is from `params.document.uri`
Url::from_str(&uri)
Url::from_str(uri)
.ok()
.and_then(|url| url.to_file_path().ok())
.expect("should convert to path"),
Expand Down Expand Up @@ -247,7 +247,7 @@ impl LanguageServer for Backend {

async fn did_close(&self, params: DidCloseTextDocumentParams) {
let uri = params.text_document.uri.to_string();
self.diagnostics_report_map.remove(&uri);
self.diagnostics_report_map.pin().remove(&uri);
}

async fn code_action(&self, params: CodeActionParams) -> Result<Option<CodeActionResponse>> {
Expand All @@ -258,7 +258,7 @@ impl LanguageServer for Backend {
.is_some_and(|only| only.contains(&CODE_ACTION_KIND_SOURCE_FIX_ALL_OXC));

let mut code_actions_vec: Vec<CodeActionOrCommand> = vec![];
if let Some(value) = self.diagnostics_report_map.get(&uri.to_string()) {
if let Some(value) = self.diagnostics_report_map.pin().get(&uri.to_string()) {
let reports = value.iter().filter(|r| {
r.diagnostic.range == params.range
|| range_overlaps(params.range, r.diagnostic.range)
Expand Down Expand Up @@ -476,8 +476,8 @@ impl Backend {
}

async fn revalidate_open_files(&self) {
join_all(self.diagnostics_report_map.iter().map(|map| {
let url = Url::from_str(map.key()).expect("should convert to path");
join_all(self.diagnostics_report_map.pin_owned().keys().map(|key| {
let url = Url::from_str(key).expect("should convert to path");

self.handle_file_update(url, None, None)
}))
Expand Down Expand Up @@ -523,7 +523,7 @@ impl Backend {
)
.await;

self.diagnostics_report_map.insert(uri.to_string(), diagnostics);
self.diagnostics_report_map.pin().insert(uri.to_string(), diagnostics);
}
}
}
Expand Down Expand Up @@ -561,7 +561,7 @@ async fn main() {
let stdout = tokio::io::stdout();

let server_linter = ServerLinter::new();
let diagnostics_report_map = FxDashMap::default();
let diagnostics_report_map = ConcurrentHashMap::default();

let (service, socket) = LspService::build(|client| Backend {
client,
Expand Down
Loading