VidocqH / lsp-lens.nvim

Neovim plugin for displaying references and difinition infos upon functions like JB's IDEA.
MIT License
252 stars 15 forks source link

Space before Definitions #20

Open mortymacs opened 1 year ago

mortymacs commented 1 year ago

Hi,

In Go, it shows space before interfaces definitions: image

As the screenshot shows, functions and methods display correctly, but only the interface has spaces.

Cheers, Mort

mortymacs commented 1 year ago

I also saw it when I defined a type: image

mcauley-penney commented 8 months ago

I can reproduce the problem. Looking at the content of the document symbols (which are returned by the LSP itself), the start character for the range, which lsp-lens uses to figure out where to place the extmark lines, is actually 5. Notice in the image below that the range start value for the Hello function is 0.

So, this appears to be a problem with Gopls, or lsp-lens has to figure out its own way to determine the indent for each extmark line it places.

image

mortymacs commented 8 months ago

Hey @mcauley-penney, thanks for looking into this issue and providing the details. I'm on board with supporting this feature in the lsp-lens itself since it might be useful for other languages too.

VidocqH commented 8 months ago

Hey @mcauley-penney, thanks for looking into this issue and providing the details. I'm on board with supporting this feature in the lsp-lens itself since it might be useful for other languages too.

Sorry for replay late. I think it can be solved with vim.fn.indent(lnum), always placed lsp-info at the start point of the given line, but I am not sure if this will broke with some languages.

mortymacs commented 8 months ago

Hey @mcauley-penney, thanks for looking into this issue and providing the details. I'm on board with supporting this feature in the lsp-lens itself since it might be useful for other languages too.

Sorry for replay late. I think it can be solved with vim.fn.indent(lnum), always placed lsp-info at the start point of the given line, but I am not sure if this will broke with some languages.

Is it testable by something like this? :lua vim.fn.indent(5)

VidocqH commented 8 months ago

Hey @mcauley-penney, thanks for looking into this issue and providing the details. I'm on board with supporting this feature in the lsp-lens itself since it might be useful for other languages too.

Sorry for replay late. I think it can be solved with vim.fn.indent(lnum), always placed lsp-info at the start point of the given line, but I am not sure if this will broke with some languages.

Is it testable by something like this? :lua vim.fn.indent(5)

Yes, this func returns how many indents the given line have. Namely the starting point of the given line.

Official docs: :h indent()

mortymacs commented 8 months ago

I tried it, but still, I'm not sure what should I do in my LSP config. Would you please elaborate a little?

VidocqH commented 8 months ago

I tried it, but still, I'm not sure what should I do in my LSP config. Would you please elaborate a little?

Sorry for the ambiguity, this func is to get the indent of the given line which is the starting point of the line, I mean maybe we can use this func to get the indent and always display lens info at that point rather than the point provided by LSP, this will eliminate all leading spaces but I am not sure if this will broke with some language. πŸ€”

Something like this:

ζˆͺ屏2023-10-27 上午1 54 41
mortymacs commented 8 months ago

I tried it, but still, I'm not sure what should I do in my LSP config. Would you please elaborate a little?

Sorry for the ambiguity, this func is to get the indent of the given line which is the starting point of the line, I mean maybe we can use this func to get the indent and always display lens info at that point rather than the point provided by LSP, this will eliminate all leading spaces but I am not sure if this will broke with some language. πŸ€”

Something like this: ζˆͺ屏2023-10-27 上午1 54 41

No problem at all! ;) That's a good idea! It's also good to make it configurable (e.g. by_lsp or static) something like:

....
require'lsp-lens'.setup({
  ...
  advanced = {
    indent = "by_lsp",
  },
})

Also, one unrelated question, how did you enable the third section (icon Vidocq + 1) in your info? That's very interesting :)

VidocqH commented 8 months ago

I tried it, but still, I'm not sure what should I do in my LSP config. Would you please elaborate a little?

Sorry for the ambiguity, this func is to get the indent of the given line which is the starting point of the line, I mean maybe we can use this func to get the indent and always display lens info at that point rather than the point provided by LSP, this will eliminate all leading spaces but I am not sure if this will broke with some language. πŸ€” Something like this: ζˆͺ屏2023-10-27 上午1 54 41

No problem at all! ;) That's a good idea! It's also good to make it configurable (e.g. by_lsp or static) something like:

....
require'lsp-lens'.setup({
  ...
  advanced = {
    indent = "by_lsp",
  },
})

Also, one unrelated question, how did you enable the third section (icon Vidocq + 1) in your info? That's very interesting :)

Okay, let it configurable is good LOL.

that section is git_author, I finished it two days ago and testing it for myself to see if there's a bug. Plan to publish it in next few days. πŸ˜‚

mortymacs commented 4 months ago

I just found another situation when the indentation needs to be adjusted image