Skip to content

Commit

Permalink
fix(cli): correctly compute ignored files
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Sep 4, 2023
1 parent f62f24f commit 09b564e
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
#### Enhancements

- Biome now reports a diagnostics when a `rome.json` file is found.
- Fix a case where Biome couldn't compute correctly the ignored files when the VSC integration is enabled.

### Configuration
### Editors
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {

impl LoggingFilter {
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
let filter = if meta.target().starts_with("biome") {
// TODO: keep "rome" until all internal crates are moved to "biome_"
let filter = if meta.target().starts_with("rome") {
SELF_FILTER
} else {
LevelFilter::INFO
Expand Down
Empty file.
1 change: 1 addition & 0 deletions crates/rome_cli/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
mod biome_json_support;
mod config_extends;
mod ignored_files;
80 changes: 80 additions & 0 deletions crates/rome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,86 @@ file2.js
));
}

#[test]
fn ignores_file_inside_directory() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let git_ignore = r#"
ignored/
"#;

let code1 = r#"array.map(sentence => sentence.split(' ')).flat();"#;
let code2 = r#"foo.call(); bar.call();"#;

// ignored files
let file_path1 = Path::new("ignored/file1.js");
fs.insert(file_path1.into(), code1.as_bytes());
let file_path2 = Path::new("ignored/file2.js");
fs.insert(file_path2.into(), code2.as_bytes());

// git folder
let git_folder = Path::new("./.git");
fs.insert(git_folder.into(), "".as_bytes());

// git ignore file
let ignore_file = Path::new("./.gitignore");
fs.insert(ignore_file.into(), git_ignore.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("check"),
("--vcs-enabled=true"),
("--vcs-client-kind=git"),
("--vcs-use-ignore-file=true"),
("--vcs-root=."),
("--apply-unsafe"),
file_path1.as_os_str().to_str().unwrap(),
file_path2.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

let mut file = fs
.open(file_path1)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, code1);
drop(file);

let mut file = fs
.open(file_path2)
.expect("formatting target file was removed by the CLI");

let mut content = String::new();
file.read_to_string(&mut content)
.expect("failed to read file from memory FS");

assert_eq!(content, code2);

drop(file);

content.clear();

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"ignores_file_inside_directory",
fs,
console,
result,
));
}

#[test]
fn ignore_vcs_os_independent_parse() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
source: crates/rome_cli/tests/snap_test.rs
expression: content
---
## `./.git`

```git
```

## `./.gitignore`

```gitignore
ignored/
```

## `ignored/file1.js`

```js
array.map(sentence => sentence.split(' ')).flat();
```

## `ignored/file2.js`

```js
foo.call(); bar.call();
```

# Termination Message

```block
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× No files were processed in the specified paths.
```

# Emitted Messages

```block
Fixed 0 file(s) in <TIME>
```


46 changes: 28 additions & 18 deletions crates/rome_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl LSPServer {
requests::syntax_tree::syntax_tree(&self.session, &url).map_err(into_lsp_error)
}

#[tracing::instrument(skip(self), name = "rome/rage", level = "debug")]
#[tracing::instrument(skip(self), name = "biome/rage", level = "debug")]
async fn rage(&self, params: RageParams) -> LspResult<RageResult> {
let mut entries = vec![
RageEntry::section("Server"),
Expand Down Expand Up @@ -118,7 +118,7 @@ impl LSPServer {
let mut capabilities = CapabilitySet::default();

capabilities.add_capability(
"rome_did_change_extension_settings",
"biome_did_change_extension_settings",
"workspace/didChangeConfiguration",
if self.session.can_register_did_change_configuration() {
CapabilityStatus::Enable(None)
Expand All @@ -128,25 +128,35 @@ impl LSPServer {
);

capabilities.add_capability(
"rome_did_change_workspace_settings",
"biome_did_change_workspace_settings",
"workspace/didChangeWatchedFiles",
if let Some(base_path) = self.session.base_path() {
CapabilityStatus::Enable(Some(json!(DidChangeWatchedFilesRegistrationOptions {
watchers: vec![FileSystemWatcher {
glob_pattern: GlobPattern::String(format!(
"{}/biome.json",
base_path.display()
)),
kind: Some(WatchKind::all()),
}],
watchers: vec![
FileSystemWatcher {
glob_pattern: GlobPattern::String(format!(
"{}/biome.json",
base_path.display()
)),
kind: Some(WatchKind::all()),
},
// TODO: Biome 2.0 remove it
FileSystemWatcher {
glob_pattern: GlobPattern::String(format!(
"{}/rome.json",
base_path.display()
)),
kind: Some(WatchKind::all()),
}
],
})))
} else {
CapabilityStatus::Disable
},
);

capabilities.add_capability(
"rome_formatting",
"biome_formatting",
"textDocument/formatting",
if self.session.is_linting_and_formatting_disabled() {
CapabilityStatus::Disable
Expand All @@ -155,7 +165,7 @@ impl LSPServer {
},
);
capabilities.add_capability(
"rome_range_formatting",
"biome_range_formatting",
"textDocument/rangeFormatting",
if self.session.is_linting_and_formatting_disabled() {
CapabilityStatus::Disable
Expand All @@ -164,7 +174,7 @@ impl LSPServer {
},
);
capabilities.add_capability(
"rome_on_type_formatting",
"biome_on_type_formatting",
"textDocument/onTypeFormatting",
if self.session.is_linting_and_formatting_disabled() {
CapabilityStatus::Disable
Expand All @@ -183,7 +193,7 @@ impl LSPServer {
};

capabilities.add_capability(
"rome_rename",
"biome_rename",
"textDocument/rename",
if rename {
CapabilityStatus::Enable(None)
Expand Down Expand Up @@ -431,9 +441,9 @@ type Sessions = Arc<Mutex<HashMap<SessionKey, SessionHandle>>>;
macro_rules! workspace_method {
( $builder:ident, $method:ident ) => {
$builder = $builder.custom_method(
concat!("rome/", stringify!($method)),
concat!("biome/", stringify!($method)),
|server: &LSPServer, params| {
let span = tracing::trace_span!(concat!("rome/", stringify!($method)), params = ?params).or_current();
let span = tracing::trace_span!(concat!("biome/", stringify!($method)), params = ?params).or_current();

let workspace = server.session.workspace.clone();
let result = spawn_blocking(move || {
Expand Down Expand Up @@ -526,13 +536,13 @@ impl ServerFactory {
builder = builder.custom_method(SYNTAX_TREE_REQUEST, LSPServer::syntax_tree_request);

// "shutdown" is not part of the Workspace API
builder = builder.custom_method("rome/shutdown", |server: &LSPServer, (): ()| {
builder = builder.custom_method("biome/shutdown", |server: &LSPServer, (): ()| {
info!("Sending shutdown signal");
server.session.broadcast_shutdown();
ready(Ok(Some(())))
});

builder = builder.custom_method("rome/rage", LSPServer::rage);
builder = builder.custom_method("biome/rage", LSPServer::rage);

workspace_method!(builder, file_features);
workspace_method!(builder, is_path_ignored);
Expand Down
40 changes: 20 additions & 20 deletions crates/rome_service/src/workspace/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
}

pub fn shutdown(self) -> Result<(), WorkspaceError> {
self.request("rome/shutdown", ())
self.request("biome/shutdown", ())
}
}

Expand All @@ -104,84 +104,84 @@ where
&self,
params: SupportsFeatureParams,
) -> Result<FileFeaturesResult, WorkspaceError> {
self.request("rome/file_features", params)
self.request("biome/file_features", params)
}

fn is_path_ignored(&self, params: IsPathIgnoredParams) -> Result<bool, WorkspaceError> {
self.request("rome/is_path_ignored", params)
self.request("biome/is_path_ignored", params)
}

fn update_settings(&self, params: UpdateSettingsParams) -> Result<(), WorkspaceError> {
self.request("rome/update_settings", params)
self.request("biome/update_settings", params)
}

fn open_file(&self, params: OpenFileParams) -> Result<(), WorkspaceError> {
self.request("rome/open_file", params)
self.request("biome/open_file", params)
}

fn get_syntax_tree(
&self,
params: GetSyntaxTreeParams,
) -> Result<GetSyntaxTreeResult, WorkspaceError> {
self.request("rome/get_syntax_tree", params)
self.request("biome/get_syntax_tree", params)
}

fn get_control_flow_graph(
&self,
params: GetControlFlowGraphParams,
) -> Result<String, WorkspaceError> {
self.request("rome/get_control_flow_graph", params)
self.request("biome/get_control_flow_graph", params)
}

fn get_formatter_ir(&self, params: GetFormatterIRParams) -> Result<String, WorkspaceError> {
self.request("rome/get_formatter_ir", params)
self.request("biome/get_formatter_ir", params)
}

fn get_file_content(&self, params: GetFileContentParams) -> Result<String, WorkspaceError> {
self.request("rome/get_file_content", params)
self.request("biome/get_file_content", params)
}

fn change_file(&self, params: ChangeFileParams) -> Result<(), WorkspaceError> {
self.request("rome/change_file", params)
self.request("biome/change_file", params)
}

fn close_file(&self, params: CloseFileParams) -> Result<(), WorkspaceError> {
self.request("rome/close_file", params)
self.request("biome/close_file", params)
}

fn pull_diagnostics(
&self,
params: PullDiagnosticsParams,
) -> Result<PullDiagnosticsResult, WorkspaceError> {
self.request("rome/pull_diagnostics", params)
self.request("biome/pull_diagnostics", params)
}

fn pull_actions(&self, params: PullActionsParams) -> Result<PullActionsResult, WorkspaceError> {
self.request("rome/pull_actions", params)
self.request("biome/pull_actions", params)
}

fn format_file(&self, params: FormatFileParams) -> Result<Printed, WorkspaceError> {
self.request("rome/format_file", params)
self.request("biome/format_file", params)
}

fn format_range(&self, params: FormatRangeParams) -> Result<Printed, WorkspaceError> {
self.request("rome/format_range", params)
self.request("biome/format_range", params)
}

fn format_on_type(&self, params: FormatOnTypeParams) -> Result<Printed, WorkspaceError> {
self.request("rome/format_on_type", params)
self.request("biome/format_on_type", params)
}

fn fix_file(&self, params: FixFileParams) -> Result<FixFileResult, WorkspaceError> {
self.request("rome/fix_file", params)
self.request("biome/fix_file", params)
}

fn rename(&self, params: RenameParams) -> Result<RenameResult, WorkspaceError> {
self.request("rome/rename", params)
self.request("biome/rename", params)
}

fn rage(&self, params: RageParams) -> Result<RageResult, WorkspaceError> {
self.request("rome/rage", params)
self.request("biome/rage", params)
}

fn server_info(&self) -> Option<&ServerInfo> {
Expand All @@ -192,6 +192,6 @@ where
&self,
params: OrganizeImportsParams,
) -> Result<OrganizeImportsResult, WorkspaceError> {
self.request("rome/organize_imports", params)
self.request("biome/organize_imports", params)
}
}
Loading

0 comments on commit 09b564e

Please sign in to comment.