-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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(lsp): use deno_ast and cache swc ASTs #11780
refactor(lsp): use deno_ast and cache swc ASTs #11780
Conversation
…at would be better.
…dency and it may be added to the standard library in the future.
@@ -91,14 +89,10 @@ pub async fn format( | |||
|
|||
/// Formats markdown (using https://github.com/dprint/dprint-plugin-markdown) and its code blocks | |||
/// (ts/tsx, js/jsx). | |||
fn format_markdown( | |||
file_text: &str, | |||
ts_config: dprint_plugin_typescript::configuration::Configuration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config objects were being needlessly passed around.
@kitsonk this is in draft because of the failing build due to problems I encountered integrating, but it's good enough for a review. (see the PR description—I shouldn't have updated swc in the crates so that I wouldn't need to bump deno_doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, while it may only appreciably impact performance with large documents, especially with the language server, we likely want to take every ms.
…ppened in refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the massive PR, but at least it removes 700 lines of code from the CLI 🙂
@@ -488,7 +488,7 @@ fn syntax_error() { | |||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), | |||
false, | |||
); | |||
assert!(out.ends_with("parse error: Expected ';', '}' or <eof> at 1:7\n2\n")); | |||
assert!(out.ends_with("parse error: Expected ';', '}' or <eof> at 1:8\n2\n")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The column in parse errors is now 1-indexed for display (matches line number and what is shown in editors).
@@ -52,7 +52,7 @@ pub struct File { | |||
/// The resolved media type for the file. | |||
pub media_type: MediaType, | |||
/// The source of the file as a string. | |||
pub source: String, | |||
pub source: Arc<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should reduce memory usage and clones by using Arc<String>
for the file text as much as possible (I may have still missed some areas). I didn't profile this or anything, but seems like something we should proactively do and is what's done in deno_ast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's reasonable 👍
// reuse by other processes | ||
let (_, lint_diagnostics) = | ||
linter.lint(specifier.to_string(), source_code.to_string())?; | ||
let lint_diagnostics = linter.lint_with_ast(parsed_source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
let source = language_server | ||
.get_text_content(specifier) | ||
.ok_or_else(|| anyhow!("Missing text content: {}", specifier))?; | ||
let media_type = language_server | ||
.get_media_type(specifier) | ||
.ok_or_else(|| anyhow!("Missing media type: {}", specifier))?; | ||
// we swallow parsed errors, as they are meaningless here. | ||
// TODO(@kitsonk) consider caching previous code_lens results to return if | ||
// there is a parse error to avoid issues of lenses popping in and out | ||
if let Ok(parsed_module) = | ||
analysis::parse_module(specifier, &source, &media_type) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see so much code being removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change integrates
deno_ast
and lazily caches/reuses swc AST in the language server.I've yet to come up with a benchmark I think is worthwhile to have... given that swc is already so fast this change is only noticable with very large files. I would say this isn't so much a performance improvement, but rather just a refactoring.
Closes #11345
Closes #11854