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

Find workspace root #247

Merged
merged 3 commits into from
Oct 11, 2024
Merged

Find workspace root #247

merged 3 commits into from
Oct 11, 2024

Conversation

dimfeld
Copy link
Contributor

@dimfeld dimfeld commented Oct 11, 2024

This provides a few methods of finding the workspace root (see comment below) and updates the calls that use workspace_uri to use it.

Closes #244
Closes #238
Supersedes #243

…ory for one of the project root files.

The default list of project root files was copied from codeium.vim.
Copy link
Collaborator

@pqn pqn left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, definitely the existing relative path wasn't computed correctly. The workspace_uri argument is expected to be file:///path/to/workspace (convention changed from relative path to the other path components basically) just like theabsolute_uri argument is expected to be file:///path/to/workspace/foo/bar.txt.

end

-- From the CWD, walk up the tree looking for a directory that contains one of the project root files
local candidates = config.options.project_root_paths
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the source of candidates should be vim.lsp.buf.list_workspace_folders()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like a good idea. Personally I'm actually still on coc.nvim so I'll probably keep the project_root_paths option as a fallback when list_workspace_folders returns nothing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds reasonable.

@dimfeld
Copy link
Contributor Author

dimfeld commented Oct 11, 2024

Ok I think this is looking good now. I implemented a 4-step process:

  1. If provided, call an optional function to find the workspace root which can be provided to setup. I'm using this in my personal config to ask coc.nvim for the workspace root.
  2. Query the LSP support for the workspace folders
  3. Search upwards in the filesystem for one of the markers (.git, package.json, etc.)
  4. Use the CWD

Confirmed that the chat context is working too. The filename appears in the "current" thing above the textbox and when I ask it "what is this file" it references the correct one :)
CleanShot 2024-10-11 at 08 49 24@2x

@dimfeld dimfeld marked this pull request as ready for review October 11, 2024 18:47
@dimfeld dimfeld changed the title Find workspace root by searching upward for relevant paths Find workspace root Oct 11, 2024
@saranshsaini saranshsaini self-requested a review October 11, 2024 20:29
@saranshsaini saranshsaini merged commit 8394850 into Exafunction:main Oct 11, 2024
2 checks passed
-- From the CWD, walk up the tree looking for a directory that contains one of the project root files
local candidates = config.options.workspace_root.paths
local result = vim.fs.find(candidates, {
path = cwd,
Copy link
Contributor

Choose a reason for hiding this comment

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

@dimfeld where is this cwd variable coming from? I notice that this pr fixed things for mac, but on windows it fails. Seems the failure is because this cwd variable is nil. How does it get populated on mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, that was missed when I was moving around some code. M.get_project_root should pass its wd variable to _get_project_root for the value of cwd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted #248 as a fix

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.

get_relative_path is not returning actual relative path Codeium Chat doesn't work in Neovim
3 participants