Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: foundations for LSP workspaces support #2589

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ schemars = { version = "0.8.12" }
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
similar = "2.5.0"
slotmap = "1.0.7"
smallvec = { version = "1.10.0", features = ["union", "const_new"] }
syn = "1.0.109"
tokio = { version = "1.36.0" }
Expand Down
11 changes: 10 additions & 1 deletion crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use biome_configuration::{
};
use biome_deserialize::Merge;
use biome_service::configuration::PartialConfigurationExt;
use biome_service::workspace::RegisterProjectFolderParams;
use biome_service::{
configuration::{load_configuration, LoadedConfiguration},
workspace::{FixFileMode, UpdateSettingsParams},
Expand Down Expand Up @@ -129,11 +130,19 @@ pub(crate) fn check(
paths = _paths;
}

session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;

session
.app
.workspace
.update_settings(UpdateSettingsParams {
working_directory: session.app.fs.working_directory(),
workspace_directory: session.app.fs.working_directory(),
configuration: fs_configuration,
vcs_base_path,
gitignore_matches,
Expand Down
12 changes: 10 additions & 2 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use biome_deserialize::Merge;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

pub(crate) struct CiCommandPayload {
Expand Down Expand Up @@ -106,12 +106,20 @@ pub(crate) fn ci(session: CliSession, payload: CiCommandPayload) -> Result<(), C
paths = get_changed_files(&session.app.fs, &fs_configuration, since)?;
}

session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;

session
.app
.workspace
.update_settings(UpdateSettingsParams {
configuration: fs_configuration,
working_directory: session.app.fs.working_directory(),
workspace_directory: session.app.fs.working_directory(),
vcs_base_path,
gitignore_matches,
})?;
Expand Down
12 changes: 10 additions & 2 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use biome_diagnostics::PrintDiagnostic;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::workspace::UpdateSettingsParams;
use biome_service::workspace::{RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

pub(crate) struct FormatCommandPayload {
Expand Down Expand Up @@ -165,11 +165,19 @@ pub(crate) fn format(
paths = _paths;
}

session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;

session
.app
.workspace
.update_settings(UpdateSettingsParams {
working_directory: session.app.fs.working_directory(),
workspace_directory: session.app.fs.working_directory(),
configuration,
vcs_base_path,
gitignore_matches,
Expand Down
12 changes: 10 additions & 2 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use biome_deserialize::Merge;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::workspace::{FixFileMode, UpdateSettingsParams};
use biome_service::workspace::{FixFileMode, RegisterProjectFolderParams, UpdateSettingsParams};
use std::ffi::OsString;

pub(crate) struct LintCommandPayload {
Expand Down Expand Up @@ -106,11 +106,19 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(

let stdin = get_stdin(stdin_file_path, &mut *session.app.console, "lint")?;

session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;

session
.app
.workspace
.update_settings(UpdateSettingsParams {
working_directory: session.app.fs.working_directory(),
workspace_directory: session.app.fs.working_directory(),
configuration: fs_configuration,
vcs_base_path,
gitignore_matches,
Expand Down
9 changes: 9 additions & 0 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::execute::{execute_mode, Execution, TraversalMode};
use crate::{setup_cli_subscriber, CliDiagnostic, CliSession};
use biome_console::{markup, ConsoleExt};
use biome_service::configuration::{load_configuration, LoadedConfiguration};
use biome_service::workspace::RegisterProjectFolderParams;

use super::MigrateSubCommand;

Expand All @@ -23,6 +24,14 @@ pub(crate) fn migrate(
} = load_configuration(&session.app.fs, base_path)?;
setup_cli_subscriber(cli_options.log_level, cli_options.log_kind);

session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;

if let (Some(path), Some(directory_path)) = (file_path, directory_path) {
execute_mode(
Execution::new(TraversalMode::Migrate {
Expand Down
13 changes: 11 additions & 2 deletions crates/biome_cli/src/commands/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use biome_deserialize::Merge;
use biome_service::configuration::{
load_configuration, LoadedConfiguration, PartialConfigurationExt,
};
use biome_service::workspace::{ParsePatternParams, UpdateSettingsParams};
use biome_service::workspace::{
ParsePatternParams, RegisterProjectFolderParams, UpdateSettingsParams,
};
use std::ffi::OsString;

pub(crate) struct SearchCommandPayload {
Expand Down Expand Up @@ -59,8 +61,15 @@ pub(crate) fn search(
configuration.retrieve_gitignore_matches(&session.app.fs, vcs_base_path.as_deref())?;

let workspace = &session.app.workspace;
session
.app
.workspace
.register_project_folder(RegisterProjectFolderParams {
path: session.app.fs.working_directory(),
set_as_current_workspace: true,
})?;
workspace.update_settings(UpdateSettingsParams {
working_directory: session.app.fs.working_directory(),
workspace_directory: session.app.fs.working_directory(),
configuration,
vcs_base_path,
gitignore_matches,
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_formatter/tests/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_formatter::{FormatResult, Formatted, Printed};
use biome_formatter_test::TestFormatLanguage;
use biome_parser::AnyParse;
use biome_rowan::{SyntaxNode, TextRange};
use biome_service::settings::{ServiceLanguage, WorkspaceSettings};
use biome_service::settings::{ServiceLanguage, Settings};

#[derive(Default)]
pub struct CssTestFormatLanguage {
Expand All @@ -26,7 +26,7 @@ impl TestFormatLanguage for CssTestFormatLanguage {

fn to_language_settings<'a>(
&self,
settings: &'a WorkspaceSettings,
settings: &'a Settings,
) -> &'a <Self::ServiceLanguage as ServiceLanguage>::FormatterSettings {
&settings.languages.css.formatter
}
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_formatter_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use biome_parser::AnyParse;
use biome_rowan::{SyntaxNode, TextRange};
use biome_service::file_handlers::DocumentFileSource;
use biome_service::settings::ServiceLanguage;
use biome_service::settings::WorkspaceSettings;
use biome_service::settings::Settings;

pub mod check_reformat;
pub mod diff_report;
Expand All @@ -25,7 +25,7 @@ pub trait TestFormatLanguage {

fn to_language_settings<'a>(
&self,
settings: &'a WorkspaceSettings,
settings: &'a Settings,
) -> &'a <Self::ServiceLanguage as ServiceLanguage>::FormatterSettings;

fn format_node(
Expand All @@ -45,7 +45,7 @@ pub trait TestFormatLanguage {

fn to_options(
&self,
settings: &WorkspaceSettings,
settings: &Settings,
file_source: &DocumentFileSource,
) -> <Self::ServiceLanguage as ServiceLanguage>::FormatOptions {
let language_settings = self.to_language_settings(settings);
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_formatter_test/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use biome_formatter::{FormatOptions, Printed};
use biome_fs::BiomePath;
use biome_parser::AnyParse;
use biome_rowan::{TextRange, TextSize};
use biome_service::settings::{ServiceLanguage, WorkspaceSettings};
use biome_service::settings::{ServiceLanguage, Settings};
use biome_service::workspace::{DocumentFileSource, FeaturesBuilder, SupportsFeatureParams};
use biome_service::App;
use std::ops::Range;
Expand Down Expand Up @@ -222,7 +222,7 @@ where
if options_path.exists() {
let mut options_path = BiomePath::new(&options_path);

let mut settings = WorkspaceSettings::default();
let mut settings = Settings::default();
// SAFETY: we checked its existence already, we assume we have rights to read it
let (test_options, diagnostics) = deserialize_from_str::<PartialConfiguration>(
options_path.get_buffer_from_file().as_str(),
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use std::fs::{self, read_to_string};
use std::{fs::File, io, io::Write, ops::Deref, path::PathBuf};

#[derive(Debug, Clone, Eq, Hash, PartialEq)]
#[derive(Debug, Clone, Eq, Hash, PartialEq, Default)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_formatter/tests/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_js_parser::{parse, JsParserOptions};
use biome_js_syntax::{JsFileSource, JsLanguage};
use biome_parser::AnyParse;
use biome_rowan::SyntaxNode;
use biome_service::settings::{ServiceLanguage, WorkspaceSettings};
use biome_service::settings::{ServiceLanguage, Settings};
use biome_text_size::TextRange;

pub struct JsTestFormatLanguage {
Expand Down Expand Up @@ -36,7 +36,7 @@ impl TestFormatLanguage for JsTestFormatLanguage {

fn to_language_settings<'a>(
&self,
settings: &'a WorkspaceSettings,
settings: &'a Settings,
) -> &'a <Self::ServiceLanguage as ServiceLanguage>::FormatterSettings {
&settings.languages.javascript.formatter
}
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_json_formatter/tests/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_json_parser::{parse_json, JsonParserOptions};
use biome_json_syntax::{JsonFileSource, JsonLanguage};
use biome_parser::AnyParse;
use biome_rowan::{SyntaxNode, TextRange};
use biome_service::settings::{ServiceLanguage, WorkspaceSettings};
use biome_service::settings::{ServiceLanguage, Settings};
use serde::{Deserialize, Serialize};

#[derive(Default)]
Expand All @@ -27,7 +27,7 @@ impl TestFormatLanguage for JsonTestFormatLanguage {

fn to_language_settings<'a>(
&self,
settings: &'a WorkspaceSettings,
settings: &'a Settings,
) -> &'a <Self::ServiceLanguage as ServiceLanguage>::FormatterSettings {
&settings.languages.json.formatter
}
Expand Down
18 changes: 10 additions & 8 deletions crates/biome_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,24 @@ impl LanguageServer for LSPServer {
self.is_initialized.store(true, Ordering::Relaxed);

let server_capabilities = server_capabilities(&params.capabilities);
if params.root_path.is_some() {
warn!("The Biome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead");
}

if let Some(_folders) = &params.workspace_folders {
warn!("The Biome Server was initialized with the `workspace_folders` parameter: this is unsupported at the moment, use `root_uri` instead");
}

self.session.initialize(
params.capabilities,
params.client_info.map(|client_info| ClientInformation {
name: client_info.name,
version: client_info.version,
}),
params.root_uri,
params.workspace_folders,
);

if params.root_path.is_some() {
warn!("The Biome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead");
}

if params.workspace_folders.is_some() {
warn!("The Biome Server was initialized with the `workspace_folders` parameter: this is unsupported at the moment, use `root_uri` instead");
}

//
let init = InitializeResult {
capabilities: server_capabilities,
Expand Down Expand Up @@ -574,6 +575,7 @@ impl ServerFactory {
workspace_method!(builder, file_features);
workspace_method!(builder, is_path_ignored);
workspace_method!(builder, update_settings);
workspace_method!(builder, register_project_folder);
workspace_method!(builder, open_file);
workspace_method!(builder, open_project);
workspace_method!(builder, update_current_project);
Expand Down
Loading
Loading