How do I subscribe to another LSP server events in my LSP server - language-server-protocol

I am new to LSP servers development, so tell me if the question is hard to understand :)
I am writing an LSP server for a newly developed language that works with its own kind of files in a code project, but also makes use of existing classes that may be written in C# (or Java, Python, etc.).
The project must first be compiled to use existing code files, and the reflection must be used after that.
The problem is how to subscribe to changes, performed by other LSP servers: for example, how can my server know that C# LSP server has performed a rename or some other operation?
I cannot add a C# LSP server client to my server since LSP protocol states that it supports "one server - one tool" model.
Another use case example to make it more clear what I am looking for:
lets say I want to rename a CSS class in my .css file
I would like my HTML LSP server to catch such a rename (performed by CSS LSP server) and update all the mentions of the CSS class in HTML files

Related

Vimscript function calls from terminal emulator

I have Language server client (vim-lsc) installed as a plugin in neovim. This client interacts with a language server for couple of languages, like python or R, and provides features like autocomplete, variable renaming etc...
One feature I want to use is the code execution, in which case you can select the part of the code and then send it to the LSP server for evaluation and get the response for it. I can do a similar thing if I create a terminal emulator "term://python" and copy paste the code there, but in this way there are two "servers" running, one via the LSP server and other from the terminal, similar to what vim-matlab does.
I was hoping to be able to do both with just one instance of python or R or MATLAb running. If there is a way to send the typed "command" in the terminal emulator to the LSP server via the vim-lsc plugin, then the job can be done with just one instance running.
I also thought of making a vimscript which creates a buffer that emulates terminal (like how Conque or vim-terminal do) and then capture and pass the commands via that script. Although, I was not able to figure out how those plugin made the prompt and command output non-modifiable but keeping the current typed command by the user modifiable.
My reason for preferring the LSP route and not opting for plugins like vimterm is that they don't provide various features like autocomplete and refactoring.
Any suggestions would be welcome. Thanks.
EDIT: I would like to clarify that as of now I don't think vim-lsc has the capability to send the executeCommand request. I wrote a small vimscript (sepatate code) which is able to do that. I plan to submit a pull-request in time and have the feature available in vim-lsc, hence the inclusion of vim-lsc in the description. Apologies for the confusion.
If it's part of the LSP protocol, and you can indeed send the code to the LSP server for execution, then it's not one that vim-lsc has implemented; I can't find it in the helpfile. Best thing you can do is search on the issue page and/or post about the feature yourself.

Run node script when VSCode extension is active

I'm developing a VSCode extension using LSP (Language Server Protocol) which is activated whenever the user opens a file with extension '.ext'.
It has the following structure:
I'm already using the Language Client/Server libraries for VSCode, and the language validation consists on a web server deployed locally on a random free port containing ANTLR4 classes which receive the content of the file the user is modifying. After analysing this content, it sends a response via HTTP to the Language Server part containing the diagnostics about the received code snippet. Then, Server sends the adapted diagnostics to Client, so they can be used by VSCode to inform the user about the errors.
The extension works fine, but I have to run the language validation server manually whenever I want to use the extension (which is writen in Node.js). Is there a way to automatically start that node server whenever the extension is activated?
Thanks in advance.
The idea of starting an http server on another machine using a VS Code extension sounds strange to me, I think you can use the ANTLR-generated parser directly in your language server. If the parser is not generated in the same language as the server's, you can just re-generate it from the grammar.

Basic use of server side API and passing server side variable to client side

I've just started my IT degree and I'm a beginner to the use of APIs (and forums like this) so I am truly sorry if my question is to vaguely explained or if it is just plain stupid :), on top of that I'm not a native English speaker :P. Okay, so I'm trying to use Google trends' api which I installed in my server with putty by using sudo npm install google-trends-api. (it can be found here https://www.npmjs.com/package/google-trends-api#installation) As I undestand it, this is a server side api so the scripts that I write with the methods provided for this api will not run on an explorer as normal js files do. There is an example that makes use of the API that I found on the page which is as follows
var googleTrends = requite('google-trends-api');
googleTrends.hotTrends('US')
.then(function(results){
console.log(results);
})
.catch(function(err){
console.log(err);
});
this outputs a list of 20 items on the console when I use it on node.
I would like to know if there is a way to assign those results to a variable and then use that variable in a normal javascript script inside a html file. I do not know anything about node.js and the like, and I would like to actually do some research instead of asking here but I was going to use a different approach to acquire such information but now I've had to change my plans and do not have enough time and given I consider this is a fairly easy problem to resolve (maybe?) I would really appreciate it if someone could walk me through the basics of each step. THanks :) and have a nice day.
Your question is quite broad. Node.js is Chrome's V8 engine bundled with some libraries to do I/O and networking. This enables us to JavaScript outside of the browser and to create backend services or servers in general (in your case). I hope that you are aware of this difference :)
The first thing that you have to do, is to have a look at express.js and to create a simple server. It will not be more than 20 lines of code. Then you have to enrich this with more stuff like a template engine (handlebars.js, jade etc). You have to enable the server to serve static files that will be finally your js, css and image files. Creating this simple server you will be able to serve simple html page in the first place. On top of that you should have the client side javascript that you have to write and now you can use the module above. Unfortunately, you are not able to use this module directly on a javascript file that you will write. To be able to use this module you have to transcompile this thing into javascript that browser understand*. Remember that browser does not understand the require statement and some old browsers possibly will have issues with the promises that this module is using. These are the things that should be compiled. You have to use a tool like browserify for this and the compiled file that this will extract it must be included in the scripts of your html page.
Maybe there are quite a lot of concepts that you are not aware of or you don't understand them but spend a bit of time to understand them.
P.S.: I' ve replied under the assumption that google-trends-api module does not use things that are specific to node.js like the file-system for example.

Server side programming language/framework that support hot-reload

Is there any other server side language (with or without frameworks) that support hot-reload or live-coding, so when we develop, all we need is:
Start the web server
Edit the source code
Try on the browser (without having to restart the server)
Similar to PHP
Some other language that I know able to do this:
ruby/sinatra
sinatra-reloader gem (sometimes not working)
rerun (*
nodejs
nodules module
node-supervisor module
nodemon (*
(* automatically restart server when there are changes, not really hot-reload
Is there any other language that are able to do this? and if possible, showing the error (filename and line number, or the full stack trace) on the browser (not in the terminal/console), so I don't have to switch from code-editor then to browser and then to console to see the error.
You can try Perl with the Mojolicious framework: http://mojolicio.us/ (using the morbo server).
Can also be achived with Groovy/Java using the Grails framework: http://grails.org
You can use Erlang to work as a web server, which is designed to allow you to hot swap whole modules of code while the program is up and running. Though, the functional programming paradigm does take a little while to get used to...
How to write a simple webserver in Erlang?
I hope this helps...
I think what you ask for is actually called live-reload, hot-reload is something I believe only Erlang can truly accomplish.
By configuring and adding plugins to Grunt or Gulp, you can watch for changes in any list / kinds of files and describe any action to be initiated. Here is a plugin for Grunt. With this method, any language can gain such ability.
As a side note, Django (Python) has auto-restart as well. But that does not mean Python language has it built-in, Django uses a Grunt-like trick to restart its dev-server.
Revel for Go could do this, or Beego, the difference is Revel only recompile when there are changes on the source code and on new request (so it's more efficient), Beego recompile every time there are source code changes.
EDIT: Beego 1.3.0 remove its hot reload feature T__T

securing the source code in a node-webkit desktop application

first things first , i have seen nwsnapshot. and its not helping.
i am building an inventory management system as a desktop app using node-webkit . the project being built is using compoundjs (mvc javascript library). which have a definite folder structure (you know mvc) and multiple javascript files inside them.
the problem is nwsnapshot allows the app to have only a single snapshot file but the logic of application is spread over all the folders in different javascript files.
so how do i secure my source code before shipping it to client? Or any other work-around Or smarter way (yes, i know about obfuscating).
You can use nodewebkit command called nwsnapshot to compile the javascript code into binary which will be loaded into the app without specifying any js file
nwsnapshot --extra-code application.js application.bin
in your package.json add this:
snapshot: 'application.bin'
It really depends on what you mean by "secure".
You can obfuscate your javascript code fairly well (as well as potentially improve performance) by using the Google Closure Compiler.
I'm not aware of any off-the-shelf solutions to encrypt/decrypt your javascript, and honestly I would question the need for that.
Some people think they need to make it impossible to view their source code, because they're used to dealing with compiled languages where you only ship binaries to users. The fact is, reverse-engineering that binary code was never as difficult as some people think it is, so if there's any financial incentive, there is practically no difference between shipping source code and the traditional shipping of binaries.
Some languages have offered genuine encryption of deployed assets, such as Microsoft's SLPS. It seems to me that the market for this was so small that Microsoft gave it to a partner (just my view). The truth is that most customers are not interested in taking your source code; they're far more interested in your ability to service and support that code in an efficient manner, while they get on with their job.
You may consider to merge the JS files into one in the build process and compile it.

Resources