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

paths relative to the working directory #21

Closed
Frydac opened this issue Dec 5, 2021 · 8 comments
Closed

paths relative to the working directory #21

Frydac opened this issue Dec 5, 2021 · 8 comments

Comments

@Frydac
Copy link

Frydac commented Dec 5, 2021

Hi,

I think the relative paths work relative to the parent directory of the file I'm currently editing.
Generally I want paths relative to the project the file belongs to, which I usually setup as my vim working directory.

For me it would be fine if both the parent dir and the cwd are used initially until only a unique match exists.
Or if it is an option to choose either one or the other would also be fine for me.
Or something else you come up with.. (lsp root dir might also be a good candidate)

For now I've made a small edit locally in the plugin source so I get the relative path to my cwd, so no pressure :)

Thank you so much for all this stuff, just starting to migrate nvim with lua based plugins and built in lsp since I have holidays, I'm enjoying myself very much, and I'm amazed by cmp, great work!

@ten3roberts
Copy link

I second this. I always use project.nvim to set my cwd to the git repo. Since the program which will read the filepaths are going to look for them in the project dir, not that specific source file dir, it makes sense to have an option for paths relative to cwd.

@ten3roberts
Copy link

I'd gladly use your edit if you upload it to your github as a fork.

If your edit works well, you could open a PR and maybe get it merged without @hrsh7th doing all the work.

@hrsh7th
Copy link
Owner

hrsh7th commented Dec 7, 2021

{ name = 'path', option = {
  get_cwd = function()
  end
} }

I can merge the above API.

@ten3roberts
Copy link

How is this issue getting along.

I may be wrong, but it does not seem as if above change has been made.

@hrsh7th
Copy link
Owner

hrsh7th commented Jan 11, 2022

I thoughts someone create the PR the above design.

@ten3roberts
Copy link

I thought something like that.

As it is now, it will always lookup the current buffer name and use fs_stat now.

If I've understood it correctly, the above API allow you to exchange the source._dirname function with your own in complete, fed into 'candidates.

If that is the case, I will gladly implement it and open a PR.

Thanks so much for this plugin.

@maxnoe
Copy link

maxnoe commented Jul 11, 2024

Hi,

How should I define get_cwd If I want relative paths to be resolved from the working directory where I start vim, not the path of the file I am currently editing?

@acro5piano
Copy link

@maxnoe

This should work.

  get_cwd = function(params)
    return vim.fn.getcwd()
  end,

I've also created a small fork to have both cwd and the path of the buffer file.

https://github.com/acro5piano/cmp-path-chdir

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

No branches or pull requests

5 participants