How do “lang-servers” work within VScode? How can an extension figure out an entirely custom codebase and its functions and give me definitions on just right click?

465 views

It is crazy useful and ive no idea how it works.

Server makes me think it is a web service but it works even with like completely local code that is entirely custom and stuff.

All i know is i tend to need to compile the codebase once before it gets the new function definitions.

In: 5

18 Answers

Anonymous 0 Comments

Essentially, the IDE builds an index of some sort of your code. It basically takes all of your source code and extracts the outline of the code. Function definitions, global variables, etc.

If you have worked with C/C++ you likely know of an old school version of this. The header files. They basically outline your source file with functions and variables. You define the header file and reference it in other source files to both use it and implement it. The IDE builds something similar to this for any language and uses it to give you the definitions.

> All i know is i tend to need to compile the codebase once before it gets the new function definitions.

Depending on the language you’re using, it sometimes has to do this. Not all languages are structured in a way that makes this easy to keep up to date on the fly. It’s easier to do in languages like Java and C# because they have a fairly strict structure. Javascript can be a lot harder to deal with.

As for why it’s called a server, it’s because it’s implemented as a separate process. It’s like a server that the IDE is talking to, it’s just running locally on your computer. It’s likely using a loopback interface to communicate using TCP/IP, but it doesn’t have to. They do this for a lot of reasons. But one would be to help keep your IDE responsive while the “server” does a bunch of heavy lifting. Or if one crashes, it doesn’t cause the other to crash.

You are viewing 1 out of 18 answers, click here to view all answers.