microsoft/compose-language-service

Please add a binary to launch the server

marcdeop opened this issue · 10 comments

Would it be possible to add a binary docker-compose-language-service to launch the server?

Right now we have to execute node @microsoft/compose-language-service from the terminal.

We created a wrapper here, an exectuable docker-compose-language-service with:

#!/usr/bin/env bash

exec node $PATH_TO_MODULES/@microsoft/compose-language-service/lib/server.js" "$@"

We try to automate the configuration of the server here and it assumes the wrapper exists.

Things would be simpler if the binary existed already :-)

Thank you in advance

Thanks @marcdeop! This is an interesting idea. Are there other language services that are already doing this, that I could use as a reference?

From the top of my head:

docker-anguage-server-nodejs
yaml-language-server
vim-language-server

Hopefully is enough to give you an idea :-)

@marcdeop can you npm install the build for the PR? It's available here: https://dev.azure.com/ms-azuretools/AzCode/_build/results?buildId=58272&view=artifacts&pathAsName=false&type=publishedArtifacts. The download will come as a .ZIP which you can extract, and then do npm install /path/to/microsoft-compose-language-service-0.1.3-alpha.tgz. I think that's all these executables are supposed to be.

If that does work, I'll bump the version and release.

So... a few issues:

npm install microsoft-compose-language-service/microsoft-compose-language-service-0.1.3-alpha.tgz                                                                                                                               
npm ERR! code 128                                                                                                                                                                                                                                            
npm ERR! An unknown git error occurred                                                                                                                                                                                                                       
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/microsoft-compose-language-service/microsoft-compose-language-service-0.1.3-alpha.tgz.git                                                                                           
npm ERR! ERROR: Repository not found.                                                                                                                                                                                                                        
npm ERR! fatal: Could not read from remote repository.                                                                                                                                                                                                       
npm ERR!                                                                                                                                                                                                                                                     
npm ERR! Please make sure you have the correct access rights                                                                                                                                                                                                 
npm ERR! and the repository exists.                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                             
npm ERR! A complete log of this run can be found in:                                                                                                                                                                                                         
npm ERR!     /home/marc.deop-private/.npm/_logs/2023-02-13T20_15_20_345Z-debug-0.log

So I tried unpacking also the .tgz and running npm install inside.

The resulting file is not executable:

bin/docker-compose-langserver                          
-bash: bin/docker-compose-langserver: Permission denied

Nothing a chmod a+rx bin/docker-compose-langserver cannot fix.

Now:

./bin/docker-compose-langserver 
/usr/bin/env: ‘node\r’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

Now I am confused 😖

EDIT:
I converted the file to unix format with dos2unix bin/docker-compose-langserver and now it executes but:

node:internal/modules/cjs/loader:998                                                                                                                                                                                                                         
  throw err;                                                                                                                                                                                                                                                 
  ^                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                             
Error: Cannot find module '../lib/server'                                                                                                                                                                                                                    
Require stack:                                                                                                                                                                                                                                               
- /home/marc.deop-private/tmp/compose-language-service/bin/docker-compose-langserver                                                                                                                                                                         
    at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)                                                                                                                                                                                     
    at Module._load (node:internal/modules/cjs/loader:841:27)                                                                                                                                                                                                
    at Module.require (node:internal/modules/cjs/loader:1061:19)                                                                                                                                                                                             
    at require (node:internal/modules/cjs/helpers:103:18)                                                                                                                                                                                                    
    at Object.<anonymous> (/home/marc.deop-private/tmp/compose-language-service/bin/docker-compose-langserver:6:1)                                                                                                                                           
    at Module._compile (node:internal/modules/cjs/loader:1159:14)                                                                                                                                                                                            
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)                                                                                                                                                                                     
    at Module.load (node:internal/modules/cjs/loader:1037:32)                                                                                                                                                                                                
    at Module._load (node:internal/modules/cjs/loader:878:12)                                                                                                                                                                                                
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {                                                                                                                                                                  
  code: 'MODULE_NOT_FOUND',                                                                                                                                                                                                                                  
  requireStack: [                                                                                                                                                                                                                                            
    '/home/marc.deop-private/tmp/compose-language-service/bin/docker-compose-langserver'                                                                                                                                                                     
  ]                                                                                                                                                                                                                                                          
}                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                             
Node.js v18.12.1

I think I know what happened; Git is surreptitiously adding \r in and it's causing problems. I've seen that happen before. I have a new build that should fix that part, at least: https://dev.azure.com/ms-azuretools/AzCode/_build/results?buildId=58275&view=artifacts&pathAsName=false&type=publishedArtifacts

The install failure is, I'm guessing, due to the weird stuff we have to do with namespacing to get it to play nice with NPM. Once it's published that shouldn't be an issue but I guess for testing you'll have to extract like you did 😞

I also added the bin entry to package.json which I'd forgotten to do before. I don't know for sure but that may (or may not) fix the permissions issue so chmod isn't needed.

Interestingly, I was able to npm install the .tgz file--as long as I was in the same folder as it, not a parent folder. No idea why that is...once I did the npm install, it collects the necessary dependencies (e.g., vscode-languageserver, yaml, a few others) and seemed to work. Unpacking alone didn't work, though the error I got was different--missing vscode-languageserver.

Wohoo 🎉 :

npm install microsoft-compose-language-service-0.1.3-alpha.tgz 

added 7 packages, and audited 8 packages in 620ms

found 0 vulnerabilities

And then:

~/node_modules/\@microsoft/compose-language-service/bin/docker-compose-langserver  --stdio

Seems to be running :-)

Hey @marcdeop, I just published 0.1.3 on NPM with these changes. Let us know if it works!

@bwateratmsft : I know the ticket is closed but I wanted to let you know everything seems to be working fine.

The main two places (here and here) are way simpler now and they seem to work.

Thanks a ton for the quick response and the solution!

Awesome! Glad we could help!