Skip to content
Open
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
90 changes: 39 additions & 51 deletions Cargo.lock
Comment thread
BenjaminBrienen marked this conversation as resolved.

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

2 changes: 1 addition & 1 deletion crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ide-completion.workspace = true
indexmap.workspace = true
itertools.workspace = true
scip = "0.7.1"
lsp-types = { version = "=0.95.0", features = ["proposed"] }
lsp-types = { version = "0.4.0", package = "gen-lsp-types", features=["url"] }
parking_lot = "0.12.4"
xflags = "0.3.2"
oorandom = "11.1.5"
Expand Down
33 changes: 14 additions & 19 deletions crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,15 @@ fn run_server() -> anyhow::Result<()> {

tracing::info!("InitializeParams: {}", initialize_params);
let lsp_types::InitializeParams {
#[expect(deprecated, reason = "compatibility with old clients")]
root_uri,
mut capabilities,
workspace_folders,
capabilities,
workspace_folders_initialize_params,
initialization_options,
client_info,
..
} = from_json::<lsp_types::InitializeParams>("InitializeParams", &initialize_params)?;

// lsp-types has a typo in the `/capabilities/workspace/diagnostics` field, its typoed as `diagnostic`
if let Some(val) = initialize_params.pointer("/capabilities/workspace/diagnostics")
&& let Ok(diag_caps) = from_json::<lsp_types::DiagnosticWorkspaceClientCapabilities>(
"DiagnosticWorkspaceClientCapabilities",
val,
)
{
tracing::info!("Patching lsp-types workspace diagnostics capabilities: {diag_caps:#?}");
capabilities.workspace.get_or_insert_default().diagnostic.get_or_insert(diag_caps);
}

let root_path = match root_uri
.and_then(|it| it.to_file_path().ok())
.map(patch_path_prefix)
Expand All @@ -247,7 +237,14 @@ fn run_server() -> anyhow::Result<()> {
);
}

let workspace_roots = workspace_folders
let workspace_roots = workspace_folders_initialize_params
.workspace_folders
.and_then(|workspaces| match workspaces {
lsp_types::WorkspaceFolders::WorkspaceFolderList(workspace_folders) => {
Some(workspace_folders)
}
lsp_types::WorkspaceFolders::Null => None,
})
.map(|workspaces| {
workspaces
.into_iter()
Expand All @@ -269,12 +266,11 @@ fn run_server() -> anyhow::Result<()> {

if !error_sink.is_empty() {
use lsp_types::{
MessageType, ShowMessageParams,
notification::{Notification, ShowMessage},
MessageType, Notification as _, ShowMessageNotification, ShowMessageParams,
};
let not = lsp_server::Notification::new(
ShowMessage::METHOD.to_owned(),
ShowMessageParams { typ: MessageType::WARNING, message: error_sink.to_string() },
ShowMessageNotification::METHOD.into(),
ShowMessageParams { kind: MessageType::Warning, message: error_sink.to_string() },
);
connection.sender.send(lsp_server::Message::Notification(not)).unwrap();
}
Expand All @@ -288,7 +284,6 @@ fn run_server() -> anyhow::Result<()> {
name: String::from("rust-analyzer"),
version: Some(rust_analyzer::version().to_string()),
}),
offset_encoding: None,
};

let initialize_result = serde_json::to_value(initialize_result).unwrap();
Expand Down
19 changes: 10 additions & 9 deletions crates/rust-analyzer/src/cli/lsif.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! LSIF (language server index format) generator

use std::env;
use std::time::Instant;

Expand All @@ -10,12 +9,14 @@ use ide::{
};
use ide_db::{line_index, line_index::WideEncoding};
use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace};
use lsp_types::lsif;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use rustc_hash::FxHashMap;
use stdx::format_to;
use vendored as lsif;
use vfs::{AbsPathBuf, Vfs};

mod vendored;

use crate::{
cli::flags,
line_index::{LineEndings, LineIndex, PositionEncoding},
Expand All @@ -38,9 +39,9 @@ struct LsifManager<'a, 'w> {
#[derive(Clone, Copy)]
struct Id(i32);

impl From<Id> for lsp_types::NumberOrString {
impl From<Id> for lsp_types::Code {
fn from(Id(it): Id) -> Self {
lsp_types::NumberOrString::Number(it)
lsp_types::Code::Int(it)
}
}

Expand Down Expand Up @@ -145,7 +146,7 @@ impl LsifManager<'_, '_> {
let path = path.as_path().unwrap();
let doc_id = self.add_vertex(lsif::Vertex::Document(lsif::Document {
language_id: "rust".to_owned(),
uri: lsp_types::Url::from_file_path(path).unwrap(),
uri: lsp_types::Uri::from_file_path(path).unwrap(),
}));
self.file_map.insert(id, doc_id);
doc_id
Expand All @@ -156,7 +157,7 @@ impl LsifManager<'_, '_> {
if let Some(hover) = token.hover {
let hover_id = self.add_vertex(lsif::Vertex::HoverResult {
result: lsp_types::Hover {
contents: lsp_types::HoverContents::Markup(to_proto::markup_content(
contents: lsp_types::Contents::MarkupContent(to_proto::markup_content(
hover.markup,
ide::HoverDocFormat::Markdown,
)),
Expand Down Expand Up @@ -211,7 +212,7 @@ impl LsifManager<'_, '_> {
out_v: result_set_id.into(),
}));
let mut edges = token.references.iter().fold(
FxHashMap::<_, Vec<lsp_types::NumberOrString>>::default(),
FxHashMap::<_, Vec<lsp_types::Code>>::default(),
|mut edges, it| {
let entry = edges.entry((it.range.file_id, it.is_definition)).or_default();
entry.push((*self.range_map.get(&it.range).unwrap()).into());
Expand Down Expand Up @@ -321,9 +322,9 @@ impl flags::Lsif {
let mut lsif = LsifManager::new(&analysis, db, &vfs, out);
lsif.add_vertex(lsif::Vertex::MetaData(lsif::MetaData {
version: String::from("0.5.0"),
project_root: lsp_types::Url::from_file_path(path).unwrap(),
project_root: lsp_types::Uri::from_file_path(path).unwrap(),
position_encoding: lsif::Encoding::Utf16,
tool_info: Some(lsp_types::lsif::ToolInfo {
tool_info: Some(lsif::ToolInfo {
name: "rust-analyzer".to_owned(),
args: vec![],
version: Some(version().to_string()),
Expand Down
Loading