chore(lsp): add tests for compiler options being resolved relative the config file (#22924)

Investigation from #17298
This commit is contained in:
David Sherret 2024-03-15 10:27:43 -04:00 committed by GitHub
parent 36e6e4a009
commit ce768bac83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 84 additions and 7 deletions

View file

@ -80,12 +80,60 @@ fn lsp_tsconfig_types() {
let mut client = context.new_lsp_command().build();
client.initialize(|builder| {
builder.set_config("types.tsconfig.json");
builder
.set_config("types.tsconfig.json")
// avoid finding the declaration file via the document preload
.set_preload_limit(0);
});
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": Url::from_file_path(temp_dir.path().join("test.ts")).unwrap(),
"uri": temp_dir.uri().join("test.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "console.log(a);\n"
}
}));
assert_eq!(diagnostics.all().len(), 0);
client.shutdown();
}
#[test]
fn lsp_tsconfig_types_config_sub_dir() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
let sub_dir = temp_dir.path().join("sub_dir");
sub_dir.create_dir_all();
sub_dir.join("types.tsconfig.json").write(
r#"{
"compilerOptions": {
"types": ["./a.d.ts"]
},
"lint": {
"rules": {
"tags": []
}
}
}"#,
);
let a_dts = "// deno-lint-ignore-file no-var\ndeclare var a: string;";
sub_dir.join("a.d.ts").write(a_dts);
temp_dir.write("deno.json", "{}");
let mut client = context.new_lsp_command().build();
client.initialize(|builder| {
builder
.set_config("sub_dir/types.tsconfig.json")
// avoid finding the declaration file via the document preload
.set_preload_limit(0);
});
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.uri().join("test.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "console.log(a);\n"
@ -164,7 +212,7 @@ fn lsp_import_map() {
builder.set_import_map("import-map.json");
});
let uri = Url::from_file_path(temp_dir.path().join("a.ts")).unwrap();
let uri = temp_dir.uri().join("a.ts").unwrap();
let diagnostics = client.did_open(json!({
"textDocument": {
@ -10801,7 +10849,7 @@ fn lsp_data_urls_with_jsx_compiler_option() {
let mut client = context.new_lsp_command().build();
client.initialize_default();
let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap();
let uri = temp_dir.uri().join("main.ts").unwrap();
let diagnostics = client.did_open(json!({
"textDocument": {
@ -11683,7 +11731,7 @@ fn decorators_tc39() {
let mut client = context.new_lsp_command().build();
client.initialize_default();
let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap();
let uri = temp_dir.uri().join("main.ts").unwrap();
let diagnostics = client
.did_open(json!({
@ -11734,7 +11782,7 @@ fn decorators_ts() {
let mut client = context.new_lsp_command().build();
client.initialize_default();
let uri = Url::from_file_path(temp_dir.path().join("main.ts")).unwrap();
let uri = temp_dir.uri().join("main.ts").unwrap();
let diagnostics = client
.did_open(json!({

View file

@ -90,3 +90,4 @@ Within the file, you can use the following for matching:
- `[WILDCHARS(5)]` - match any of the next 5 characters
- `[UNORDERED_START]` followed by many lines then `[UNORDERED_END]` will match
the lines in any order (useful for non-deterministic output)
- `[# example]` - line comments start with `[#` and end with `]`

View file

@ -0,0 +1,5 @@
{
"args": "check --config sub_dir/deno.json main.ts",
"output": "main.out",
"exitCode": 1
}

View file

@ -0,0 +1,3 @@
[# It should be resolving relative the config in sub_dir instead of the cwd]
error: Module not found "file:///[WILDLINE]/sub_dir/a.d.ts".
at file:///[WILDLINE]/sub_dir/deno.json:1:1

View file

@ -0,0 +1,7 @@
{
"compilerOptions": {
"types": [
"./a.d.ts"
]
}
}

View file

@ -24,6 +24,10 @@ pub fn main() {
// todo(dsherret): the output should be changed to be terse
// when it passes, but verbose on failure
for category in &categories {
if category.tests.is_empty() {
continue; // skip output when all the tests have been filtered out
}
eprintln!();
eprintln!(" {} {}", colors::green_bold("Running"), category.name);
eprintln!();

View file

@ -668,7 +668,16 @@ pub fn wildcard_match_detailed(
// Normalize line endings
let original_text = text.replace("\r\n", "\n");
let mut current_text = original_text.as_str();
let pattern = pattern.replace("\r\n", "\n");
// normalize line endings and strip comments
let pattern = pattern
.split('\n')
.map(|line| line.trim_end_matches('\r'))
.filter(|l| {
let is_comment = l.starts_with("[#") && l.ends_with(']');
!is_comment
})
.collect::<Vec<_>>()
.join("\n");
let mut output_lines = Vec::new();
let parts = parse_wildcard_pattern_text(&pattern).unwrap();