Skip to content
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

fix(lsp): support npm workspaces and fix some resolution issues #24627

Merged
merged 15 commits into from
Jul 18, 2024

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jul 17, 2024

Makes the lsp use the same code as the rest of the cli.

Closes #24598
Closes #24505

@dsherret dsherret added the ci-draft Run the CI on draft PRs. label Jul 18, 2024
"textDocument/hover",
json!({

// project1 resolution
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is #24598

@dsherret dsherret changed the title refactor(lsp): use Workspace from deno_config fix(lsp): use Workspace from deno_config Jul 18, 2024
let discover_result = match scope.to_file_path() {
Ok(scope_dir_path) => {
let paths = [scope_dir_path];
Workspace::discover(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name Workspace is a little confusing because it actually contains information about where it started discovery from. Maybe we should rename it to WorkspaceContext or something like that? denoland/deno_config#93

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree

Copy link
Member Author

@dsherret dsherret Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

denoland/deno_config#94 -- We can also now re-org this to cache the workspace loading between discoveries.

@dsherret dsherret changed the title fix(lsp): use Workspace from deno_config fix(lsp): support npm workspaces and fix some resolution issues Jul 18, 2024
@dsherret
Copy link
Member Author

I have an example of npm workspaces working without byonm, but failing with it in the lsp for some reason. This should be good enough for the first pass though.

@dsherret dsherret marked this pull request as ready for review July 18, 2024 04:02
@dsherret dsherret removed the ci-draft Run the CI on draft PRs. label Jul 18, 2024
@@ -11917,6 +11917,11 @@ fn lsp_node_modules_dir() {

assert!(!temp_dir.path().join("node_modules").exists());

// a lockfile will be created here because someone did an explicit cache
let lockfile_path = temp_dir.path().join("deno.lock");
assert!(lockfile_path.exists());
Copy link
Member Author

@dsherret dsherret Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running deno cache creates a lockfile here so I think this is ok because it aligns with that now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree

},
"newText": "''",
"newText": "'')",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix. Should be no semis here.

Comment on lines +1136 to +1138
cached_deno_config_fs: &(dyn DenoConfigFs + Sync),
deno_json_cache: &(dyn DenoJsonCache + Sync),
pkg_json_cache: &(dyn PackageJsonCache + Sync),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: maybe we could create a wrapper like deno_unsync that would cheat the type system and not require these Sync trait bounds?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cli/lsp/config.rs Outdated Show resolved Hide resolved
@@ -11917,6 +11917,11 @@ fn lsp_node_modules_dir() {

assert!(!temp_dir.path().join("node_modules").exists());

// a lockfile will be created here because someone did an explicit cache
let lockfile_path = temp_dir.path().join("deno.lock");
assert!(lockfile_path.exists());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree

Copy link
Collaborator

@nayeemrmn nayeemrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret
Copy link
Member Author

Workspace cache for deno_config is in denoland/deno_config#95 -- I will follow up and land that in a separate PR.

@dsherret dsherret merged commit 3bda8eb into denoland:main Jul 18, 2024
17 checks passed
@dsherret dsherret deleted the refactor_lsp_deno_config branch July 18, 2024 22:16
bartlomieju pushed a commit that referenced this pull request Jul 22, 2024
Makes the lsp use the same code as the rest of the cli.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LSP workspace does not recognize package imports field in config LSP - Understand npm workspaces
3 participants