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

lsp-sample based extension – no onCompletion triggers #156

Closed
imtbl opened this issue Feb 28, 2019 · 13 comments
Closed

lsp-sample based extension – no onCompletion triggers #156

imtbl opened this issue Feb 28, 2019 · 13 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@imtbl
Copy link

imtbl commented Feb 28, 2019

I've developed an extension that's (loosely) based on lsp-sample around half a year ago. Back then, it was working fine.

Yesterday, I made some changes and updated some dependencies. But now it looks like the communication with the language server doesn't work correctly.

It initializes just fine (I'm debugging this with <ext>.trace.server and also just plain console.log() calls in the server), but the client for some reason never sends any completion requests. The defined snippets here work just fine though, so it's not like the client isn't working at all, it just doesn't want to utilize the language server after initializing it.

Reverting to the old version from around half a year ago didn't help, so I can only assume some change in a more recent version of VS Code now causes this behaviour (seems weird, but I can find no other explanation).

I've already confirmed that it's not just an issue on my local machine.

I would be glad for any help – I'm pretty sure it's just one little oversight. I've already made some more updates and added the aforementioned debug measures on the develop branch.

Steps to get this running/reproduce the issue:

  1. Clone the develop branch
  2. yarn && yarn compile
  3. Debug with Launch client
  4. Set the language to Touhou Danmakufu (dnh) or open a file with .dnh extension
  5. The server output will now show that it has initialized successfully
  6. Type a t VS Code will now suggest task, which is a snippet, but
    • no completions from the server come up (and there are quite a lot for typing t)
    • the server output shows no messages that would indicate a completion query from the client
    • and this console.log() that should happen onCompletion also doesn't get called

Thank you in advance!

@dbaeumer
Copy link
Member

dbaeumer commented Mar 4, 2019

Strange. This works for me out of the box.

  • cloned repository
  • git co develop
  • yarn install
  • yarn run compile

capture

@dbaeumer
Copy link
Member

dbaeumer commented Mar 4, 2019

Any additional info?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Mar 4, 2019
@imtbl
Copy link
Author

imtbl commented Mar 4, 2019

@dbaeumer

Hey, thanks for checking! :)

Very weird, because I've tested this on three different machines and it didn't work on any of them. I'm guessing there must be some other thing that's interfering with the client<->server communication on all of them then (even though two of them are non-dev machines and I can't think of anything running on them that could be using the same port as the language server or something like that). 🤔

In any case, I'll test it in a completely fresh environment and report back if it does indeed work there.

@imtbl
Copy link
Author

imtbl commented Mar 4, 2019

@dbaeumer

Alright, I have some more info now:

I can confirm it functioning correctly on the three machines I've tested on before if I open an existing <file>.dnh. If I create a new file via Ctrl/Cmd + N and switch to the correct language via Ctrl/Cmd + K M, I only get the snippets and not the completions from the language server. After saving that newly created file as <file 2>.dnh, the language server completions start coming up in this file as well.

I'm pretty sure this has worked by just switching the language before when I first published the extension last year – I didn't have to save a file before the client started asking the language server for completions. But maybe this has changed? Maybe there's some flag I need to set in the contributes section of package.json now?

@dbaeumer
Copy link
Member

dbaeumer commented Mar 6, 2019

@mserajnik this is expected since you only register for the file schema. If you want to get untitled files as well you need to register for them as well. Something like

  const clientOptions: LanguageClientOptions = {
    documentSelector: [
       { scheme: 'file', language: 'dnh' },
       { scheme: 'untitled', language: 'dnh' }
    ]
  }

OK to close ?

@imtbl
Copy link
Author

imtbl commented Mar 6, 2019

Thanks, works perfectly. 👍

Weird, I'm very positive this has worked with untitled files before without needing the additional selector.

Anyway, closed since this fixes my issue. Have a great day! :)

@imtbl
Copy link
Author

imtbl commented Mar 6, 2019

Sorry, need to reopen this. :/

Everything's been working fine in debug mode with the addition of the second selector for untitled files. And I've just published a new version of the extension to the marketplace that includes this change.

But when using this new version of the extension (not debug mode), the language server once again doesn't seem to be working (again, only the snippets come up) – and this time it doesn't matter if it's an untitled file or one that's already been saved.

Trying to debug with <ext>.trace.server (I've removed the setting from the published version, but re-added it locally by directly editing the package.json of the installed extension), I don't even get the selection for the channel in the Output tab now (it does work for CSS though, as described here, so I'm assuming it should work fine outside of debug mode as well).

Extension can be found here: https://marketplace.visualstudio.com/items?itemName=mserajnik.dnh

I've published it by running:

vsce package
vsce publish

If I inspect the compiled *.js files of client and server, everything looks fine to me (and so does the general structure of the installed extension). And I can't see any errors in any channel of the output tab (I'd presume something would show up in either the Extensions or Log (Extension Host) channel if there was a runtime error?).

Thank you for your time!

@imtbl imtbl reopened this Mar 6, 2019
@dbaeumer
Copy link
Member

dbaeumer commented Mar 8, 2019

@mserajnik here are some tips to trace this down:

  • add some console.log to the code. Especially make sure that your extension gets activated. Since you don't get the output channel I guess the extension is not loaded.
  • make sure that the extension is not installed inside VS Code.
  • package the extension using vsce package
  • install the extension locally using Install from VSIX command

Let me know how it goes.

@imtbl
Copy link
Author

imtbl commented Mar 9, 2019

@dbaeumer

Thanks for the suggestions. I've created a hotfix branch and tried all of this, but no luck so far.

Details of what I've done:

  • Added several console.log() calls:
  • Readded the <ext>.trace.server setting
  • Uninstalled the extension installed from the marketplace
  • Packaged the extension from the hotfix branch via vsce package and installed it via Install from VSIX
  • Confirmed that the compiled .js files look ok and that the console.log() statements have not been stripped for some reason
  • Played around with the TS config – in particular, I've tried removing "esModuleInterop": true (changed the ES-style imports accordingly) and "moduleResolution": "node" since you don't have those in the example, but that didn't make any difference, so I've reverted it again

I can now confirm:

  • When opening a .dnh file or setting the language to Touhou Danmakufu (dnh), I can see the following output in Log (Extension Host):
[2019-03-09 18:44:40.488] [exthost] [info] ExtensionService#_doActivateExtension mserajnik.dnh {"startup":false,"activationEvent":"onLanguage:dnh"}
[2019-03-09 18:44:40.488] [exthost] [info] ExtensionService#loadCommonJSModule /Users/mserajnik/.vscode/extensions/mserajnik.dnh-1.5.0/client/out/extension
  • I can see no error messages anywhere in the output
  • I can see none of the console.log() statements
  • I don't get the output channel for the language server
  • Snippets work fine (like I've mentioned before), but no completions

So, my guess would be, that for some reason, the extension gets activated (hence the ExtensionService#_doActivateExtension and ExtensionService#loadCommonJSModule and the working snippets) but the activate() function in the client gets never called.


Again, when launching the extension in debug mode, everything works as it should. The output channel comes up and I can see the communication and all the completions come up as they should. I can also see the server initialize from the console.log() statement I've put here in the language server output channel. None of the two console.log() I've put in the client show up anywhere here either though – I've checked all the output channels. Not sure about this one, but everything clearly works.

@dbaeumer
Copy link
Member

The console.log statements appear in the developer console which you can open via Help > Toggle Developer Tools. If still nothing shows up then the path to the extension JS file might be broken or the activate function isn't correctly exported.

@imtbl
Copy link
Author

imtbl commented Mar 11, 2019

@dbaeumer

Thank you! I didn't think about checking the developer console for the output. I can indeed see an error message in there when triggering the extension activation:

Activating extension 'mserajnik.dnh' failed: Cannot find module 'semver'.

It's quite a long stack, but I'll look into it now.

Edit: Just saw you've actually had the same issue and fixed it by including semver. I'll try this too.

@imtbl
Copy link
Author

imtbl commented Mar 11, 2019

I can indeed confirm that not excluding semver from the extension package has fixed the issue.

Thank you!

Closed.

@imtbl imtbl closed this as completed Mar 11, 2019
@dbaeumer
Copy link
Member

No problem. Happy you got it working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

2 participants