Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 40 ยท Extensions

Language Servers and IntelliSense

Understand how VS Code gets completions, hover info and go to definition from language servers using the Language Server Protocol, and how to tune IntelliSense.

When you type console. and a list of methods appears, or hover over a function and see its parameters, you are using IntelliSense. VS Code itself knows very little about each programming language. Instead, it talks to a separate program called a language server, which analyzes your code and answers questions such as "what can go here?" and "where is this defined?".

This lesson explains that architecture, lists the IntelliSense features you use daily, and shows the settings that tune them. The protocol demo at the end is a stand-in: it builds and reads the same kind of message that real servers exchange, but it does not start a server.

What IntelliSense includes

  • Completions (Ctrl+Space): suggestions as you type, with documentation.
  • Parameter hints (Ctrl+Shift+Space): the signature of the function you are calling.
  • Hover (Ctrl+K Ctrl+I, or the mouse): type and documentation for the symbol under the cursor.
  • Go to Definition (F12), Peek Definition (Alt+F12), Go to Type Definition, Go to Implementations (Ctrl+F12).
  • Find All References (Shift+F12).
  • Rename Symbol (F2): renames across files.
  • Diagnostics: errors and warnings, plus Quick Fixes (Ctrl+.).
  • Inlay hints: small labels such as parameter names drawn into the code.
  • Outline and breadcrumbs: structure of the current file.

Each of these is a request that VS Code sends to a language service, and each has a built-in command so the keys work the same in every language.

The Language Server Protocol

Before 2016, every editor needed its own plug-in for every language. The Language Server Protocol (LSP) changed that: one server per language, speaking JSON messages over a pipe or socket, and one small client in each editor. VS Code is the client; the server might be written in any language.

Editor and server talk JSON

You edit VS Code sends changes
Server thinks Parses and analyzes
Answers Completions, errors

Same protocol for every language.

1 / 2

A request is a JSON-RPC message with a method such as textDocument/completion, and the position in the file. The server replies with a list of items. Diagnostics go the other way: the server pushes textDocument/publishDiagnostics whenever it finds problems.

sequenceDiagram
    participant E as VS Code
    participant S as Language server
    E->>S: initialize
    S-->>E: capabilities
    E->>S: didOpen file
    S-->>E: publishDiagnostics
    E->>S: completion at line 4, column 8
    S-->>E: list of items

A shortened conversation between editor and server.

Some languages have a server built in (TypeScript has its own service). Others get one from an extension, for example Pylance for Python or rust-analyzer for Rust. Because the server is a normal program, it can crash or slow down on a huge project; the extension usually offers a Restart command.

Tuning IntelliSense

Useful settings:

JSON
{
  "editor.quickSuggestions": { "other": true, "comments": false, "strings": false },
  "editor.suggestSelection": "recentlyUsed",
  "editor.acceptSuggestionOnEnter": "on",
  "editor.parameterHints.enabled": true,
  "editor.inlayHints.enabled": "onUnlessPressed",
  "editor.snippetSuggestions": "top"
}
  • quickSuggestions controls whether the list pops up while typing in code, comments and strings.
  • suggestSelection picks which item is preselected.
  • inlayHints.enabled shows hints and hides them while you hold Ctrl+Alt.

For TypeScript and JavaScript, a tsconfig.json or jsconfig.json in the project root tells the service which files belong together, which improves completions across files. If IntelliSense seems to miss a file, check that the file is inside the project the config describes.

When IntelliSense seems wrong

  1. Wrong interpreter or SDK. For Python, pick the interpreter with Python: Select Interpreter; for Java or .NET choose the right SDK. The server analyzes with the environment you chose.
  2. Server not running. Look at the status bar and the Output panel's channel for the language.
  3. Stale analysis. Run Developer: Reload Window or the extension's restart command.
  4. Two servers. Disable one of two overlapping extensions.
  5. Huge folder. Exclude node_modules or build outputs from analysis with files.exclude, search.exclude or the language's own exclude setting.

Runnable stand-ins

The code below is not VS Code. It builds a JSON-RPC message the way an LSP client does (the Content-Length header is part of the real protocol) and models a completion server over a fixed word list.

JS Stand-in: an LSP-style message

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Stand-in: a completion server

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the Language Server Protocol standardize?

    LSP defines JSON-RPC messages between an editor (client) and a language server.
  2. 2. Which key opens Go to Definition by default?

    F12 is Go to Definition, F2 is Rename Symbol and Shift+F12 finds all references.
  3. 3. Python IntelliSense reports imports as missing even though they are installed. What is the first thing to check?

    The language server analyzes using the selected interpreter, which may be a different environment from the one with the packages.
  4. 4. Who sends diagnostics in LSP?

    Servers publish diagnostics when they have them; the editor draws squiggles from that.

Summary

  • IntelliSense is a set of features: completions, hover, definition, references, rename and diagnostics.
  • Most language smarts come from language servers that speak LSP over JSON-RPC.
  • Settings such as editor.quickSuggestions tune when suggestions appear.
  • Wrong analysis is usually the interpreter or SDK, a crashed server or a duplicate extension.
  • Restart the server or the window before changing settings at random.

Next: The Integrated Terminal