microsoft / microsoft/language-server-protocol

Proposal to add textDocument/ast

Open
#1,998 13 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request new request
Dominant language
TypeScript
Stars
13k
Forks
1k
Avg merge
6d 1h
Merged PRs (30d)
10

Description

This is a proposal to add a textDocument/ast to the LSP protocol. The idea is to have a capability that returns an AST from a selection.

  • The specification can specify naming and formatting conventions for various tokens and structures that are common across various language ASTs, to maximize code reuse, while allowing for any language AST to include any additional structures that are unique to the language. It would return the AST in JSON format.
  • It can replace treesitter in a better way, since it's using the real parser of the language, rather than what treesitter does which is to reimplement the parser in an often ad-hoc, incomplete, and bug ridden way. For example, this capability could be used for:
    • Robust, effectively error prone, syntax highlighting.
    • Code folding.
    • Auto-indentation that never messes up.
    • Any other thing tree sitter does.
  • In general, it can also be used for any sort of static analysis of the syntax of the code, which could be combined with other LSP calls to do really interesting static analysis on the editor side, to add really useful features in the future.

The following exist but don't actually result an AST:

  • textDocument/documentSymbol
    • Provides a hierarchical representation of the symbols in a document, such as classes, methods, and variables. While this doesn't give you a full AST, it offers a tree-like structure representing the code’s high-level organization.
  • textDocument/semanticTokens
    • Returns token-level semantic information about the document. This is useful for syntax highlighting and understanding the roles of various elements in the code but is not a direct representation of the AST.
  • textDocument/definition and textDocument/references
    • These requests return locations in the code related to a symbol, providing context-aware navigation that relies on an understanding of the code's structure.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing LSP request definitions, particularly textDocument/documentSymbol and textDocument/semanticTokens, and the specification's conventions for capabilities and JSON structures. Done would require an agreed scope and protocol design for textDocument/ast, including selection handling and AST naming and formatting conventions.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, typescript
Domain
api, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.