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",
"rustc-hash",
"scip",
"semver",
"serde",
"serde_json",
"sourcegen",

View file

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

View file

@ -16,6 +16,7 @@ use std::{env, fs, path::PathBuf, process::ExitCode, sync::Arc};
use anyhow::Context;
use lsp_server::Connection;
use rust_analyzer::{cli::flags, config::Config, from_json};
use semver::Version;
use tracing_subscriber::fmt::writer::BoxMakeWriter;
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 {
tracing::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default());
is_visual_studio_code = client_info.name.starts_with("Visual Studio Code");
tracing::info!(
"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
@ -210,7 +219,8 @@ fn run_server() -> anyhow::Result<()> {
})
.filter(|workspaces| !workspaces.is_empty())
.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 Err(e) = config.update(json) {
use lsp_types::{

View file

@ -32,8 +32,8 @@ impl flags::Scip {
let mut config = crate::config::Config::new(
root.clone(),
lsp_types::ClientCapabilities::default(),
/* workspace_roots = */ vec![],
/* is_visual_studio_code = */ false,
vec![],
None,
);
if let Some(p) = self.config_path {

View file

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

View file

@ -542,7 +542,7 @@ mod tests {
workspace_root.to_path_buf(),
ClientCapabilities::default(),
Vec::new(),
false,
None,
),
);
let snap = state.snapshot();

View file

@ -15,6 +15,7 @@ use ide::{
};
use ide_db::rust_doc::format_docs;
use itertools::Itertools;
use semver::VersionReq;
use serde_json::to_value;
use vfs::AbsPath;
@ -446,7 +447,15 @@ pub(crate) fn inlay_hint(
let needs_resolve = inlay_hint.needs_resolve;
let (label, tooltip, mut something_to_resolve) =
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();
None
} else {

View file

@ -171,7 +171,7 @@ impl Project<'_> {
..Default::default()
},
roots,
false,
None,
);
config.update(self.config).expect("invalid config");
config.rediscover_workspaces();