microsoft / microsoft/language-server-protocol

Semantic token `localScope`/`globalScope`/`fileScope`/`classScope` modifiers

Open
#2,152 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I would like to have the standard support scope modifiers for tokens. We're considering possibly implementing these at static-ls at work, but the lack of standardization makes it so that we probably will implement "is exported" as a code lens instead initially as most engineers won't have editors that display them.

It seems like this is a pretty broadly applicable concern: whether something is exported public API or internal API. Go considers this so important as to reserve first-character casing for communicating this information, but LSP currently doesn't have a standard way to offer it on other languages.

Prior art: https://clangd.llvm.org/features#modifiers

Clangd uses these like so:

  • fileScope: static void foo(void) has call and definition sites of foo annotated as fileScope
  • globalScope: write(2, "meow", 4) has write as globalScope and defaultLibrary. Similarly for a void bar(void); in the same file since it is exported.
  • classScope: idk, probably member variables. This functionality is really important since this is a confusing part of C++.
  • functionScope: variables which are just inside one function, e.g. int j;

I will note that in my role as a Haskell programmer classScope is not useful to us as we don't have objects with scope that behaves like C++/Java classes, but many languages have an idea of classes and it would be useful for those. I also don't know how e.g. OCaml modules should handle module-local variables. Should "is in scope because of the current module" be a modifier? Should those be "global scope" regardless?

What about nested Python functions?

IMO the most important of these to get standardized is whether something is an export (globalScope) or file-scope only, though.

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 Semantic Tokens specification and the linked clangd prior art. Determine whether scope modifiers should be standardized, how they apply across languages and nesting models, and what precise semantics and interoperability requirements a completed proposal would need.

Written by the indexing model from the issue text.

Assessment

Domain
devtools
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.