razzmatazz / csharp-language-server

Roslyn-based LSP language server for C#
MIT License
597 stars 37 forks source link

Missing method parameter completion #30

Open GroundCombo opened 2 years ago

GroundCombo commented 2 years ago

Apologies if this doesn't belong to csharp-ls, but I have no idea where to start looking and would appreciate any hints.

I'm trying to get Unity projects to work with Emacs and LSP, and I've gotten to a point where csharp-ls is starting, clearly understands the project and offers type information and references. However, I'm only getting completions for method names. So, instead of tabbable variable placeholders such as (typing "foo.")

foo.MyMethod(int bar)

it only offers

foo.MyMethod

The full method signature is shown in the echo area when I move over it, so the issue seems to be on the completion side.

The good old obsolete omnisharp-mode has been working perfectly in the same project. I'm testing this with Emacs 28.1, csharp-ls 0.4.3 and the latest lsp-mode from MELPA. lsp-mode is using the default :capf as the completion provider.

razzmatazz commented 2 years ago

Hi @GroundCombo !

I suspect you are Missing lsp textDocument/signatureHelp implementation which is missing on csharp-ls now.

I am working on this when I get spare time and this is the next thing on my queue

GroundCombo commented 2 years ago

Oh, that's good to know and explains a lot. I also tried omnisharp with lsp and it seems to offer the signatureHelp capability, but . is not in the trigger characters and the other triggers result in errors... so I'll just use omnisharp-mode for now. Thanks!

razzmatazz commented 2 years ago

I have released https://www.nuget.org/packages/csharp-ls/0.5.0 which has textDocument/signatureHelp implementation now

please check if this works for you -- not 100% this is how it should work, but it apparently works ok for me on emacs

FYI @vytautassurvila

GroundCombo commented 2 years ago

I'm seeing the signatureHelp capability now in lsp logs, but it doesn't quite seem to do the trick. Just to make sure we're on the same page, here's what I am expecting (omnisharp-mode):

Screenshot 2022-04-24 at 16 16 00

And this is what lsp-mode shows.

Screenshot 2022-04-24 at 16 02 29

signatureHelp is not being called in the above situation, only textDocument/completion. If I press < or ( after the method name, signatureHelp is called but did not show anything new.

I've attached some logs from the initialization and typing ".Add"; please let me know if you would like some additional information.

lsp-log-init.txt lsp-messages.txt lsp-completion.txt

razzmatazz commented 2 years ago

Ok, I think now I understand your problem. Not sure if this can be fixed with lsp though, in order to behave like omnisharp-emacs..

Signature help appears when you open parens after fn name and is triggered by "(" and "," chars. So this is probably too late as you want to see arg list already on the autocomplete Dropdown.

I will check if I can make the full fn signature available on autocomplete list and if it is readable.

But the part with "tabbing" between args is probably responsibility of lsp-mode and I'm not sure it provides that atm.

GroundCombo commented 2 years ago

I'm not familiar with lsp-mode's internals, but I believe it supports yasnippet for parameter placeholders, so it shouuuld work if the server provides the placeholder information.

razzmatazz commented 2 years ago

I was looking into how omnisharp-roslyn does this and it is somewhat complicated, it seems roslyn does not provide proper apis to do this easily (or did not provide it at the time omnisharp-roslyn completion service was written).. so I will keep this on my mind for a while until i figure what is the easiest way to provide this info..

currently i am thinking about doing a simple hack there and if the completion is requested after a '.' symbol then i can do a lookup for object type that goes before the dot and query actual method params for this -- but this will require me coding something that is supposedly already in roslyn, will be bug-prone and i am not particularly wiling to go that route yet..

razzmatazz commented 2 years ago

I think I might be able to do something about this after all, after browsing omnisharp-roslyn and roslyn codebase.. things are a bit complicated, but this should be implementable once I understand the APIs

I started my work in https://github.com/razzmatazz/csharp-language-server/pull/47