-
-
Notifications
You must be signed in to change notification settings - Fork 859
feat(language_server): add typeAware option
#13146
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
Merged
graphite-app
merged 1 commit into
main
from
08-16-feat_langauge_server_add_typeaware_option
Aug 26, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
crates/oxc_language_server/fixtures/linter/tsgolint/no-floating-promises/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| const promise = new Promise((resolve, _reject) => resolve("value")); | ||
| promise; | ||
|
|
||
| async function returnsPromise() { | ||
| return "value"; | ||
| } | ||
|
|
||
| returnsPromise().then(() => {}); | ||
|
|
||
| Promise.reject("value").catch(); | ||
|
|
||
| Promise.reject("value").finally(); | ||
|
|
||
| [1, 2, 3].map(async (x) => x + 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| use std::{ | ||
| path::Path, | ||
| sync::{Arc, OnceLock}, | ||
| }; | ||
|
|
||
| use oxc_linter::{ | ||
| ConfigStore, LINTABLE_EXTENSIONS, TsGoLintState, loader::LINT_PARTIAL_LOADER_EXTENSIONS, | ||
| read_to_string, | ||
| }; | ||
| use rustc_hash::FxHashSet; | ||
| use tower_lsp_server::{UriExt, lsp_types::Uri}; | ||
|
|
||
| use crate::linter::error_with_position::{ | ||
| DiagnosticReport, message_with_position_to_lsp_diagnostic_report, | ||
| }; | ||
|
|
||
| pub struct TsgoLinter { | ||
| state: TsGoLintState, | ||
| } | ||
|
|
||
| impl TsgoLinter { | ||
| pub fn new(root_uri: &Path, config_store: ConfigStore) -> Self { | ||
| let state = TsGoLintState::new(root_uri, config_store); | ||
| Self { state } | ||
| } | ||
|
|
||
| pub fn lint_file(&self, uri: &Uri, content: Option<String>) -> Option<Vec<DiagnosticReport>> { | ||
| let path = uri.to_file_path()?; | ||
|
|
||
| if !Self::should_lint_path(&path) { | ||
| return None; | ||
| } | ||
|
|
||
| let source_text = content.or_else(|| read_to_string(&path).ok())?; | ||
|
|
||
| let messages = self.state.lint_source(&Arc::from(path.as_os_str()), source_text).ok()?; | ||
|
|
||
| Some( | ||
| messages | ||
| .iter() | ||
| .map(|e| message_with_position_to_lsp_diagnostic_report(e, uri)) | ||
Sysix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .collect(), | ||
| ) | ||
| } | ||
|
|
||
| fn should_lint_path(path: &Path) -> bool { | ||
| static WANTED_EXTENSIONS: OnceLock<FxHashSet<&'static str>> = OnceLock::new(); | ||
| let wanted_exts = WANTED_EXTENSIONS.get_or_init(|| { | ||
| LINTABLE_EXTENSIONS | ||
| .iter() | ||
| .filter(|ext| !LINT_PARTIAL_LOADER_EXTENSIONS.contains(ext)) | ||
| .copied() | ||
| .collect() | ||
| }); | ||
|
|
||
| path.extension() | ||
| .and_then(std::ffi::OsStr::to_str) | ||
| .is_some_and(|ext| wanted_exts.contains(ext)) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...language_server/src/snapshots/fixtures_linter_tsgolint@no-floating-promises_index.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| --- | ||
| source: crates/oxc_language_server/src/tester.rs | ||
| input_file: crates/oxc_language_server/fixtures/linter/tsgolint/no-floating-promises/index.ts | ||
| --- | ||
| code: "typescript-eslint(no-confusing-void-expression)" | ||
| code_description.href: "None" | ||
| message: "Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function." | ||
| range: Range { start: Position { line: 0, character: 50 }, end: Position { line: 0, character: 66 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 0, character: 50 }, end: Position { line: 0, character: 66 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: Single(FixedContent { message: None, code: "{ resolve(\"value\"); }", range: Range { start: Position { line: 0, character: 49 }, end: Position { line: 0, character: 66 } } }) | ||
Boshen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| code: "typescript-eslint(no-floating-promises)" | ||
| code_description.href: "None" | ||
| message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator." | ||
| range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 8 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 8 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: Multiple([FixedContent { message: Some("Promises must be awaited."), code: "void ", range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 0 } } }, FixedContent { message: Some("Promises must be awaited."), code: "await ", range: Range { start: Position { line: 1, character: 0 }, end: Position { line: 1, character: 0 } } }]) | ||
|
|
||
|
|
||
| code: "typescript-eslint(no-floating-promises)" | ||
| code_description.href: "None" | ||
| message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator." | ||
| range: Range { start: Position { line: 7, character: 0 }, end: Position { line: 7, character: 32 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 7, character: 0 }, end: Position { line: 7, character: 32 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: Multiple([FixedContent { message: Some("Promises must be awaited."), code: "void ", range: Range { start: Position { line: 7, character: 0 }, end: Position { line: 7, character: 0 } } }, FixedContent { message: Some("Promises must be awaited."), code: "await ", range: Range { start: Position { line: 7, character: 0 }, end: Position { line: 7, character: 0 } } }]) | ||
|
|
||
|
|
||
| code: "typescript-eslint(no-floating-promises)" | ||
| code_description.href: "None" | ||
| message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator." | ||
| range: Range { start: Position { line: 9, character: 0 }, end: Position { line: 9, character: 32 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 9, character: 0 }, end: Position { line: 9, character: 32 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: Multiple([FixedContent { message: Some("Promises must be awaited."), code: "void ", range: Range { start: Position { line: 9, character: 0 }, end: Position { line: 9, character: 0 } } }, FixedContent { message: Some("Promises must be awaited."), code: "await ", range: Range { start: Position { line: 9, character: 0 }, end: Position { line: 9, character: 0 } } }]) | ||
|
|
||
|
|
||
| code: "typescript-eslint(no-floating-promises)" | ||
| code_description.href: "None" | ||
| message: "Promises must be awaited.\nhelp: The promise must end with a call to .catch, or end with a call to .then with a rejection handler, or be explicitly marked as ignored with the `void` operator." | ||
| range: Range { start: Position { line: 11, character: 0 }, end: Position { line: 11, character: 34 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 11, character: 0 }, end: Position { line: 11, character: 34 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: Multiple([FixedContent { message: Some("Promises must be awaited."), code: "void ", range: Range { start: Position { line: 11, character: 0 }, end: Position { line: 11, character: 0 } } }, FixedContent { message: Some("Promises must be awaited."), code: "await ", range: Range { start: Position { line: 11, character: 0 }, end: Position { line: 11, character: 0 } } }]) | ||
|
|
||
|
|
||
| code: "typescript-eslint(no-floating-promises)" | ||
| code_description.href: "None" | ||
| message: "An array of Promises may be unintentional.\nhelp: Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking the expression as ignored with the `void` operator." | ||
| range: Range { start: Position { line: 13, character: 0 }, end: Position { line: 13, character: 34 } } | ||
| related_information[0].message: "" | ||
| related_information[0].location.uri: "file://<variable>/fixtures/linter/tsgolint/no-floating-promises/index.ts" | ||
| related_information[0].location.range: Range { start: Position { line: 13, character: 0 }, end: Position { line: 13, character: 34 } } | ||
| severity: Some(Warning) | ||
| source: Some("oxc") | ||
| tags: None | ||
| fixed: None | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.