Skip to content

Commit 9ea32c3

Browse files
switch out lsp-types for gen-lsp-types
1 parent 4c57da3 commit 9ea32c3

41 files changed

Lines changed: 2459 additions & 2433 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 61 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rust-analyzer/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ide-completion.workspace = true
2929
indexmap.workspace = true
3030
itertools.workspace = true
3131
scip = "0.7.1"
32-
lsp-types = { version = "=0.95.0", features = ["proposed"] }
32+
lsp-types = { version = "0.4.0", package = "gen-lsp-types" }
3333
parking_lot = "0.12.4"
3434
xflags = "0.3.2"
3535
oorandom = "11.1.5"
@@ -53,6 +53,8 @@ semver.workspace = true
5353
memchr = "2.7.5"
5454
cargo_metadata.workspace = true
5555
process-wrap.workspace = true
56+
strum = "0.28.0"
57+
strum_macros = "0.28.0"
5658
dhat = { version = "0.3.3", optional = true }
5759

5860
cfg.workspace = true

crates/rust-analyzer/src/bin/main.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc};
1414

1515
use anyhow::Context;
1616
use lsp_server::Connection;
17-
use paths::Utf8PathBuf;
17+
use paths::{Utf8Component, Utf8PathBuf, Utf8Prefix};
1818
use rust_analyzer::{
1919
cli::flags,
2020
config::{Config, ConfigChange, ConfigErrors},
@@ -207,29 +207,18 @@ fn run_server() -> anyhow::Result<()> {
207207

208208
tracing::info!("InitializeParams: {}", initialize_params);
209209
let lsp_types::InitializeParams {
210+
#[expect(deprecated, reason = "migration TODO")]
210211
root_uri,
211-
mut capabilities,
212-
workspace_folders,
212+
capabilities,
213+
workspace_folders_initialize_params,
213214
initialization_options,
214215
client_info,
215216
..
216217
} = from_json::<lsp_types::InitializeParams>("InitializeParams", &initialize_params)?;
217218

218-
// lsp-types has a typo in the `/capabilities/workspace/diagnostics` field, its typoed as `diagnostic`
219-
if let Some(val) = initialize_params.pointer("/capabilities/workspace/diagnostics")
220-
&& let Ok(diag_caps) = from_json::<lsp_types::DiagnosticWorkspaceClientCapabilities>(
221-
"DiagnosticWorkspaceClientCapabilities",
222-
val,
223-
)
224-
{
225-
tracing::info!("Patching lsp-types workspace diagnostics capabilities: {diag_caps:#?}");
226-
capabilities.workspace.get_or_insert_default().diagnostic.get_or_insert(diag_caps);
227-
}
228-
229219
let root_path = match root_uri
230-
.and_then(|it| it.to_file_path().ok())
220+
.map(|it| Utf8PathBuf::from(it.to_string().to_owned()))
231221
.map(patch_path_prefix)
232-
.and_then(|it| Utf8PathBuf::from_path_buf(it).ok())
233222
.and_then(|it| AbsPathBuf::try_from(it).ok())
234223
{
235224
Some(it) => it,
@@ -247,13 +236,19 @@ fn run_server() -> anyhow::Result<()> {
247236
);
248237
}
249238

250-
let workspace_roots = workspace_folders
239+
let workspace_roots = workspace_folders_initialize_params
240+
.workspace_folders
241+
.and_then(|workspaces| match workspaces {
242+
lsp_types::WorkspaceFolders::WorkspaceFolderList(workspace_folders) => {
243+
Some(workspace_folders)
244+
}
245+
lsp_types::WorkspaceFolders::Null => None,
246+
})
251247
.map(|workspaces| {
252248
workspaces
253249
.into_iter()
254-
.filter_map(|it| it.uri.to_file_path().ok())
250+
.map(|it| Utf8PathBuf::from(it.uri.to_string()))
255251
.map(patch_path_prefix)
256-
.filter_map(|it| Utf8PathBuf::from_path_buf(it).ok())
257252
.filter_map(|it| AbsPathBuf::try_from(it).ok())
258253
.collect::<Vec<_>>()
259254
})
@@ -269,12 +264,11 @@ fn run_server() -> anyhow::Result<()> {
269264

270265
if !error_sink.is_empty() {
271266
use lsp_types::{
272-
MessageType, ShowMessageParams,
273-
notification::{Notification, ShowMessage},
267+
MessageType, Notification as _, ShowMessageNotification, ShowMessageParams,
274268
};
275269
let not = lsp_server::Notification::new(
276-
ShowMessage::METHOD.to_owned(),
277-
ShowMessageParams { typ: MessageType::WARNING, message: error_sink.to_string() },
270+
ShowMessageNotification::METHOD.into(),
271+
ShowMessageParams { kind: MessageType::Warning, message: error_sink.to_string() },
278272
);
279273
connection.sender.send(lsp_server::Message::Notification(not)).unwrap();
280274
}
@@ -288,7 +282,6 @@ fn run_server() -> anyhow::Result<()> {
288282
name: String::from("rust-analyzer"),
289283
version: Some(rust_analyzer::version().to_string()),
290284
}),
291-
offset_encoding: None,
292285
};
293286

294287
let initialize_result = serde_json::to_value(initialize_result).unwrap();
@@ -325,8 +318,7 @@ fn run_server() -> anyhow::Result<()> {
325318
Ok(())
326319
}
327320

328-
fn patch_path_prefix(path: PathBuf) -> PathBuf {
329-
use std::path::{Component, Prefix};
321+
fn patch_path_prefix(path: Utf8PathBuf) -> Utf8PathBuf {
330322
if cfg!(windows) {
331323
// VSCode might report paths with the file drive in lowercase, but this can mess
332324
// with env vars set by tools and build scripts executed by r-a such that it invalidates
@@ -335,17 +327,17 @@ fn patch_path_prefix(path: PathBuf) -> PathBuf {
335327
// (doing it conditionally is a pain because std::path::Prefix always reports uppercase letters on windows)
336328
let mut comps = path.components();
337329
match comps.next() {
338-
Some(Component::Prefix(prefix)) => {
330+
Some(Utf8Component::Prefix(prefix)) => {
339331
let prefix = match prefix.kind() {
340-
Prefix::Disk(d) => {
332+
Utf8Prefix::Disk(d) => {
341333
format!("{}:", d.to_ascii_uppercase() as char)
342334
}
343-
Prefix::VerbatimDisk(d) => {
335+
Utf8Prefix::VerbatimDisk(d) => {
344336
format!(r"\\?\{}:", d.to_ascii_uppercase() as char)
345337
}
346338
_ => return path,
347339
};
348-
let mut path = PathBuf::new();
340+
let mut path = Utf8PathBuf::new();
349341
path.push(prefix);
350342
path.extend(comps);
351343
path

0 commit comments

Comments
 (0)