Track vscode version for conditional bug server sided bugfixes

This commit is contained in:
Lukas Wirth 2024-03-11 10:24:57 +01:00
parent 57a0ad4343
commit 0dbaccd484
8 changed files with 44 additions and 22 deletions

1
Cargo.lock generated
View File

@ -1597,6 +1597,7 @@ dependencies = [
"rayon", "rayon",
"rustc-hash", "rustc-hash",
"scip", "scip",
"semver",
"serde", "serde",
"serde_json", "serde_json",
"sourcegen", "sourcegen",

View File

@ -42,6 +42,7 @@ triomphe.workspace = true
nohash-hasher.workspace = true nohash-hasher.workspace = true
always-assert = "0.2.0" always-assert = "0.2.0"
walkdir = "2.3.2" walkdir = "2.3.2"
semver.workspace = true
cfg.workspace = true cfg.workspace = true
flycheck.workspace = true flycheck.workspace = true

View File

@ -16,6 +16,7 @@
use anyhow::Context; use anyhow::Context;
use lsp_server::Connection; use lsp_server::Connection;
use rust_analyzer::{cli::flags, config::Config, from_json}; use rust_analyzer::{cli::flags, config::Config, from_json};
use semver::Version;
use tracing_subscriber::fmt::writer::BoxMakeWriter; use tracing_subscriber::fmt::writer::BoxMakeWriter;
use vfs::AbsPathBuf; use vfs::AbsPathBuf;
@ -193,10 +194,18 @@ fn run_server() -> anyhow::Result<()> {
} }
}; };
let mut is_visual_studio_code = false; let mut visual_studio_code_version = None;
if let Some(client_info) = client_info { if let Some(client_info) = client_info {
tracing::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); tracing::info!(
is_visual_studio_code = client_info.name.starts_with("Visual Studio Code"); "Client '{}' {}",
client_info.name,
client_info.version.as_deref().unwrap_or_default()
);
visual_studio_code_version = client_info
.name
.starts_with("Visual Studio Code")
.then(|| client_info.version.as_deref().map(Version::parse).and_then(Result::ok))
.flatten();
} }
let workspace_roots = workspace_folders let workspace_roots = workspace_folders
@ -210,7 +219,8 @@ fn run_server() -> anyhow::Result<()> {
}) })
.filter(|workspaces| !workspaces.is_empty()) .filter(|workspaces| !workspaces.is_empty())
.unwrap_or_else(|| vec![root_path.clone()]); .unwrap_or_else(|| vec![root_path.clone()]);
let mut config = Config::new(root_path, capabilities, workspace_roots, is_visual_studio_code); let mut config =
Config::new(root_path, capabilities, workspace_roots, visual_studio_code_version);
if let Some(json) = initialization_options { if let Some(json) = initialization_options {
if let Err(e) = config.update(json) { if let Err(e) = config.update(json) {
use lsp_types::{ use lsp_types::{

View File

@ -32,8 +32,8 @@ pub fn run(self) -> anyhow::Result<()> {
let mut config = crate::config::Config::new( let mut config = crate::config::Config::new(
root.clone(), root.clone(),
lsp_types::ClientCapabilities::default(), lsp_types::ClientCapabilities::default(),
/* workspace_roots = */ vec![], vec![],
/* is_visual_studio_code = */ false, None,
); );
if let Some(p) = self.config_path { if let Some(p) = self.config_path {

View File

@ -31,6 +31,7 @@
CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustLibSource, CargoConfig, CargoFeatures, ProjectJson, ProjectJsonData, ProjectManifest, RustLibSource,
}; };
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use semver::Version;
use serde::{de::DeserializeOwned, Deserialize}; use serde::{de::DeserializeOwned, Deserialize};
use stdx::format_to_acc; use stdx::format_to_acc;
use vfs::{AbsPath, AbsPathBuf}; use vfs::{AbsPath, AbsPathBuf};
@ -624,7 +625,7 @@ pub struct Config {
data: ConfigData, data: ConfigData,
detached_files: Vec<AbsPathBuf>, detached_files: Vec<AbsPathBuf>,
snippets: Vec<Snippet>, snippets: Vec<Snippet>,
is_visual_studio_code: bool, visual_studio_code_version: Option<Version>,
} }
type ParallelCachePrimingNumThreads = u8; type ParallelCachePrimingNumThreads = u8;
@ -823,7 +824,7 @@ pub fn new(
root_path: AbsPathBuf, root_path: AbsPathBuf,
caps: ClientCapabilities, caps: ClientCapabilities,
workspace_roots: Vec<AbsPathBuf>, workspace_roots: Vec<AbsPathBuf>,
is_visual_studio_code: bool, visual_studio_code_version: Option<Version>,
) -> Self { ) -> Self {
Config { Config {
caps, caps,
@ -833,7 +834,7 @@ pub fn new(
root_path, root_path,
snippets: Default::default(), snippets: Default::default(),
workspace_roots, workspace_roots,
is_visual_studio_code, visual_studio_code_version,
} }
} }
@ -1778,10 +1779,10 @@ pub fn typing_autoclose_angle(&self) -> bool {
self.data.typing_autoClosingAngleBrackets_enable self.data.typing_autoClosingAngleBrackets_enable
} }
// FIXME: VSCode seems to work wrong sometimes, see https://github.com/microsoft/vscode/issues/193124 // VSCode is our reference implementation, so we allow ourselves to work around issues by
// hence, distinguish it for now. // special casing certain versions
pub fn is_visual_studio_code(&self) -> bool { pub fn visual_studio_code_version(&self) -> Option<&Version> {
self.is_visual_studio_code self.visual_studio_code_version.as_ref()
} }
} }
// Deserialization definitions // Deserialization definitions
@ -2694,7 +2695,7 @@ fn proc_macro_srv_null() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({
@ -2710,7 +2711,7 @@ fn proc_macro_srv_abs() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({
@ -2726,7 +2727,7 @@ fn proc_macro_srv_rel() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({
@ -2745,7 +2746,7 @@ fn cargo_target_dir_unset() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({
@ -2764,7 +2765,7 @@ fn cargo_target_dir_subdir() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({
@ -2783,7 +2784,7 @@ fn cargo_target_dir_relative_dir() {
AbsPathBuf::try_from(project_root()).unwrap(), AbsPathBuf::try_from(project_root()).unwrap(),
Default::default(), Default::default(),
vec![], vec![],
false, None,
); );
config config
.update(serde_json::json!({ .update(serde_json::json!({

View File

@ -542,7 +542,7 @@ fn check_with_config(config: DiagnosticsMapConfig, diagnostics_json: &str, expec
workspace_root.to_path_buf(), workspace_root.to_path_buf(),
ClientCapabilities::default(), ClientCapabilities::default(),
Vec::new(), Vec::new(),
false, None,
), ),
); );
let snap = state.snapshot(); let snap = state.snapshot();

View File

@ -15,6 +15,7 @@
}; };
use ide_db::rust_doc::format_docs; use ide_db::rust_doc::format_docs;
use itertools::Itertools; use itertools::Itertools;
use semver::VersionReq;
use serde_json::to_value; use serde_json::to_value;
use vfs::AbsPath; use vfs::AbsPath;
@ -446,7 +447,15 @@ pub(crate) fn inlay_hint(
let needs_resolve = inlay_hint.needs_resolve; let needs_resolve = inlay_hint.needs_resolve;
let (label, tooltip, mut something_to_resolve) = let (label, tooltip, mut something_to_resolve) =
inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?; inlay_hint_label(snap, fields_to_resolve, needs_resolve, inlay_hint.label)?;
let text_edits = if needs_resolve && fields_to_resolve.resolve_text_edits {
let text_edits = if snap
.config
.visual_studio_code_version()
// https://github.com/microsoft/vscode/issues/193124
.map_or(true, |version| VersionReq::parse(">=1.86.0").unwrap().matches(version))
&& needs_resolve
&& fields_to_resolve.resolve_text_edits
{
something_to_resolve |= inlay_hint.text_edit.is_some(); something_to_resolve |= inlay_hint.text_edit.is_some();
None None
} else { } else {

View File

@ -171,7 +171,7 @@ pub(crate) fn server(self) -> Server {
..Default::default() ..Default::default()
}, },
roots, roots,
false, None,
); );
config.update(self.config).expect("invalid config"); config.update(self.config).expect("invalid config");
config.rediscover_workspaces(); config.rediscover_workspaces();