fix(rome_lsp, vscode): load config from custom base path
MODIFY
Cargo.lock
Cargo.lock
@@ -1793,6 +1793,7 @@ dependencies = [
"schemars",
"serde",
"serde_json",
+ "tracing",
]
[[package]]

MODIFY
crates/rome_cli/src/commands/check.rs
crates/rome_cli/src/commands/check.rs
@@ -7,7 +7,7 @@ use rome_service::workspace::{FixFileMode, UpdateSettingsParams};
/// Handler for the "check" command of the Rome CLI
pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs)?;
+ let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();
let max_diagnostics: Option<u16> = session

MODIFY
crates/rome_cli/src/commands/ci.rs
crates/rome_cli/src/commands/ci.rs
@@ -7,7 +7,7 @@ use super::format::apply_format_settings_from_cli;
/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs)?;
+ let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();
if let Some(configuration) = configuration {

MODIFY
crates/rome_cli/src/commands/format.rs
crates/rome_cli/src/commands/format.rs
@@ -7,7 +7,7 @@ use crate::{execute_mode, CliSession, Execution, Termination, TraversalMode};
/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs)?;
+ let configuration = load_config(&session.app.fs, None)?;
let mut workspace_settings = WorkspaceSettings::default();
if let Some(configuration) = configuration {

MODIFY
crates/rome_lsp/src/server.rs
crates/rome_lsp/src/server.rs
-use std::sync::Arc;
-
use crate::capabilities::server_capabilities;
use crate::requests::syntax_tree::{SyntaxTreePayload, SYNTAX_TREE_REQUEST};
use crate::session::Session;
use crate::utils::into_lsp_error;
use crate::{handlers, requests};
use futures::future::ready;
-use rome_service::{load_config, workspace, Workspace};
+use rome_service::{workspace, Workspace};
+use std::sync::Arc;
use tokio::io::{AsyncRead, AsyncWrite};
use tower_lsp::jsonrpc::Result as LspResult;
use tower_lsp::{lsp_types::*, ClientSocket};
@@ -48,6 +47,10 @@ impl LanguageServer for LSPServer {
.unwrap()
.replace(params.capabilities);
+ if let Some(uri) = params.root_uri {
+ self.session.root_uri.write().unwrap().replace(uri);
+ }
+
let init = InitializeResult {
capabilities: server_capabilities(),
server_info: Some(ServerInfo {
@@ -65,21 +68,7 @@ impl LanguageServer for LSPServer {
info!("Attempting to load the configuration from 'rome.json' file");
- match load_config(&self.session.fs) {
- Ok(Some(configuration)) => {
- info!("Configuration found, and it is valid!");
- self.session
- .configuration
- .write()
- .unwrap()
- .replace(configuration);
- }
- Err(err) => {
- error!("Couldn't load the configuration file, reason:\n {}", err);
- }
- _ => {}
- };
-
+ self.session.update_configuration().await;
self.session.fetch_client_configuration().await;
let msg = format!("Server initialized with PID: {}", std::process::id());

MODIFY
crates/rome_lsp/src/session.rs
crates/rome_lsp/src/session.rs
@@ -11,13 +11,15 @@ use rome_fs::{FileSystem, OsFileSystem, RomePath};
use rome_service::configuration::Configuration;
use rome_service::workspace::UpdateSettingsParams;
use rome_service::workspace::{FeatureName, PullDiagnosticsParams, SupportsFeatureParams};
-use rome_service::Workspace;
+use rome_service::{load_config, Workspace};
use rome_service::{DynRef, RomeError};
use std::collections::HashMap;
+use std::path::PathBuf;
use std::sync::Arc;
use std::sync::RwLock;
use tower_lsp::lsp_types;
-use tracing::{error, trace};
+use tower_lsp::lsp_types::Url;
+use tracing::{error, info, trace};
/// Represents the state of an LSP server session.
pub(crate) struct Session {
@@ -37,6 +39,8 @@ pub(crate) struct Session {
/// The configuration coming from `rome.json` file
pub(crate) configuration: RwLock<Option<Configuration>>,
+ pub(crate) root_uri: RwLock<Option<Url>>,
+
documents: RwLock<HashMap<lsp_types::Url, Document>>,
url_interner: RwLock<UrlInterner>,
}
@@ -48,6 +52,7 @@ impl Session {
let url_interner = Default::default();
let config = RwLock::new(Config::new());
let configuration = RwLock::new(None);
+ let root_uri = RwLock::new(None);
Self {
client,
client_capabilities,
@@ -57,6 +62,7 @@ impl Session {
config,
fs: DynRef::Owned(Box::new(OsFileSystem)),
configuration,
+ root_uri,
}
}
@@ -159,6 +165,23 @@ impl Session {
== Some(true)
}
+ /// This function attempts to read the configuration from the root URI
+ pub(crate) async fn update_configuration(&self) {
+ let root_uri = self.root_uri.read().unwrap();
+ let base_path = root_uri.as_ref().map(|uri| PathBuf::from(uri.path()));
+
+ match load_config(&self.fs, base_path) {
+ Ok(Some(configuration)) => {
+ info!("Configuration found, and it is valid!");
+ self.configuration.write().unwrap().replace(configuration);
+ }
+ Err(err) => {
+ error!("Couldn't load the configuration file, reason:\n {}", err);
+ }
+ _ => {}
+ };
+ }
+
/// Requests "workspace/configuration" from client and updates Session config
pub(crate) async fn fetch_client_configuration(&self) {
let item = lsp_types::ConfigurationItem {
@@ -191,9 +214,13 @@ impl Session {
&configuration
);
- self.workspace
- .update_settings(UpdateSettingsParams { configuration })
- .ok()?;
+ let result = self
+ .workspace
+ .update_settings(UpdateSettingsParams { configuration });
+
+ if let Err(error) = result {
+ error!("{:?}", &error)
+ }
}
Some(())

MODIFY
crates/rome_service/Cargo.toml
crates/rome_service/Cargo.toml
@@ -27,6 +27,7 @@ rome_rowan = { path = "../rome_rowan", features = ["serde"] }
rome_text_edit = { path = "../rome_text_edit", features = ["serde"] }
indexmap = { version = "1.9.1", features = ["serde"] }
schemars = { version = "0.8.10", features = ["indexmap1"], optional = true }
+tracing = { version = "0.1.31", default-features = false, features = ["std"] }
[features]
schemars = ["dep:schemars", "rome_formatter/serde", "rome_js_factory"]

MODIFY
crates/rome_service/src/configuration/mod.rs
crates/rome_service/src/configuration/mod.rs
@@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter};
use std::io::ErrorKind;
use std::path::PathBuf;
+use tracing::{error, info};
mod formatter;
mod javascript;
@@ -113,12 +114,21 @@ impl Display for ConfigurationError {
/// This function is responsible to load the rome configuration.
///
-/// The `file_system` will read the configuration file
+/// The `file_system` will read the configuration file. A base path can be passed
pub fn load_config(
file_system: &DynRef<dyn FileSystem>,
+ base_path: Option<PathBuf>,
) -> Result<Option<Configuration>, RomeError> {
let config_name = file_system.config_name();
- let configuration_path = PathBuf::from(config_name);
+ let configuration_path = if let Some(base_path) = base_path {
+ base_path.join(config_name)
+ } else {
+ PathBuf::from(config_name)
+ };
+ info!(
+ "Attempting to load the configuration file at path {:?}",
+ configuration_path
+ );
let options = OpenOptions::default().read(true).write(true);
let file = file_system.open_with_options(&configuration_path, options);
match file {
@@ -140,6 +150,11 @@ pub fn load_config(
if err.kind() != ErrorKind::NotFound {
return Err(RomeError::CantReadFile(configuration_path));
}
+ error!(
+ "Could not find the file configuration at {:?}",
+ configuration_path.display()
+ );
+ error!("Reason: {:?}", err);
Ok(None)
}
}

MODIFY
editors/vscode/package-lock.json
editors/vscode/package-lock.json
{
"name": "rome",
- "version": "0.10.0",
+ "version": "0.13.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "rome",
- "version": "0.10.0",
+ "version": "0.13.0",
"license": "MIT",
"dependencies": {
"vscode-languageclient": "^8.0.2"
},
"devDependencies": {
"@types/node": "^18.0.0",
- "@types/vscode": "^1.68.1",
+ "@types/vscode": "^1.70.0",
"esbuild": "^0.14.47",
"rome": "next",
"typescript": "^4.5.2",
- "vsce": "^2.10.0"
+ "vsce": "^2.11.0"
},
"engines": {
"npm": "^8",
"dev": true
},
"node_modules/@types/vscode": {
- "version": "1.68.1",
- "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.68.1.tgz",
- "integrity": "sha512-fXlaq13NT5yHh6yZ3c+UxXloTSk34mIvsNFYyQCeO5Po2BLFAwz7EZT4kQ43B64/aPcnAenyWy3QasrTofBOnQ==",
+ "version": "1.70.0",
+ "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.70.0.tgz",
+ "integrity": "sha512-3/9Fz0F2eBgwciazc94Ien+9u1elnjFg9YAhvAb3qDy/WeFWD9VrOPU7CIytryOVUdbxus8uzL4VZYONA0gDtA==",
"dev": true
},
"node_modules/ansi-regex": {
"dev": true
},
"node_modules/vsce": {
- "version": "2.10.0",
- "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.10.0.tgz",
- "integrity": "sha512-b+wB3XMapEi368g64klSM6uylllZdNutseqbNY+tUoHYSy6g2NwnlWuAGKDQTYc0IqfDUjUFRQBpPgA89Q+Fyw==",
+ "version": "2.11.0",
+ "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.11.0.tgz",
+ "integrity": "sha512-pr9Y0va/HCer0tTifeqaUrK24JJSpRd6oLeF/PY6FtrY41e+lwxiAq6jfMXx4ShAZglYg2rFKoKROwa7E7SEqQ==",
"dev": true,
"dependencies": {
"azure-devops-node-api": "^11.0.1",
"dev": true
},
"@types/vscode": {
- "version": "1.68.1",
- "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.68.1.tgz",
- "integrity": "sha512-fXlaq13NT5yHh6yZ3c+UxXloTSk34mIvsNFYyQCeO5Po2BLFAwz7EZT4kQ43B64/aPcnAenyWy3QasrTofBOnQ==",
+ "version": "1.70.0",
+ "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.70.0.tgz",
+ "integrity": "sha512-3/9Fz0F2eBgwciazc94Ien+9u1elnjFg9YAhvAb3qDy/WeFWD9VrOPU7CIytryOVUdbxus8uzL4VZYONA0gDtA==",
"dev": true
},
"ansi-regex": {
"dev": true
},
"vsce": {
- "version": "2.10.0",
- "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.10.0.tgz",
- "integrity": "sha512-b+wB3XMapEi368g64klSM6uylllZdNutseqbNY+tUoHYSy6g2NwnlWuAGKDQTYc0IqfDUjUFRQBpPgA89Q+Fyw==",
+ "version": "2.11.0",
+ "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.11.0.tgz",
+ "integrity": "sha512-pr9Y0va/HCer0tTifeqaUrK24JJSpRd6oLeF/PY6FtrY41e+lwxiAq6jfMXx4ShAZglYg2rFKoKROwa7E7SEqQ==",
"dev": true,
"requires": {
"azure-devops-node-api": "^11.0.1",

MODIFY
editors/vscode/package.json
editors/vscode/package.json
"url": "https://github.com/rome/tools/issues"
},
"engines": {
- "vscode": "^1.68.1",
+ "vscode": "^1.70.0",
"npm": "^8"
},
"contributes": {
},
"devDependencies": {
"@types/node": "^18.0.0",
- "@types/vscode": "^1.68.1",
+ "@types/vscode": "^1.70.0",
"typescript": "^4.5.2",
- "vsce": "^2.10.0",
+ "vsce": "^2.11.0",
"esbuild": "^0.14.47",
"rome": "next"
}

fix(rome_lsp, vscode): load config from custom base path (#3131)