Skip to content

Commit

Permalink
fix(typescript): fix LSP interpretation of file named foo.tsx.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Oct 19, 2023
1 parent ad6ee67 commit 44f3f16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Semantic Versioning.
[E0034][] ("redeclaration of variable").
* `(a?, ...b) => ReturnType` in a TypeScript type no longer falsely reports
[E0379][] ("optional parameter cannot be followed by a required parameter").
* LSP: A file named `a.tsxbanana.ts` is no longer recognized as a
TypeScript JSX file. It is now recognized as a non-JSX TypeScript
file.
* Nested `module` declarations no longer falsely report [E0361][]. E0361's
message has been changed:
* Before: "module with string name is only allowed at the top level"
Expand Down
3 changes: 2 additions & 1 deletion src/quick-lint-js/util/classify-path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See end of file for extended copyright information.

#include <cstddef>
#include <quick-lint-js/container/string-view.h>
#include <quick-lint-js/port/char8.h>
#include <quick-lint-js/util/classify-path.h>
#include <quick-lint-js/util/uri.h>
Expand All @@ -12,7 +13,7 @@ Path_Classification classify_uri(String8_View uri) {
String8_View base_name = uri_base_name(uri);
return Path_Classification{
.typescript_definition = base_name.find(u8".d."_sv) != base_name.npos,
.typescript_jsx = base_name.find(u8".tsx"_sv) != base_name.npos,
.typescript_jsx = ends_with(base_name, u8".tsx"_sv),
};
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/test-lsp-language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ TEST(Test_LSP_Language, typescript_file_without_d_or_tsx_is_source) {
<< ".d. in containing directory should be ignored";
}

{
const LSP_Language* language =
LSP_Language::find("typescript"sv, u8"file:///folder/test.tsx.ts"_sv);
ASSERT_NE(language, nullptr);
EXPECT_FALSE(language->lint_options.jsx)
<< ".tsx in file name but not in extension should be ignored";
}

// TODO(strager): Query parameters should be ignored.
// TODO(strager): Fragments should be ignored.
}
Expand Down

0 comments on commit 44f3f16

Please sign in to comment.