microsoft / microsoft/vscode-cpptools

Add textmate scope for declarations and definitions

Open
#8,489 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request Feature: Colorization Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Type: Feature Request

I tried to create a color theme that all name introduction (like declarations and definitions) are bold. However, it's not possible to unambiguously select all of those.

For example, here's a struct definition and usage:

struct MyStruct {}; // 1

MyStruct myInstance; // 2

auto function() -> decltype(myInstance) { // 3
    MyStruct myVar; // 4
    return myVar;
}

I tried to make MyStruct in 1, myInstance in 2, function in 3, myVar in 4 all bold. However, any attempt to make them bold also resulted in MyStruct being bold in 2, but it's a usage of MyStruct, not it's definition. Then any attempt to make myInstance bold in 2 also resulted in myInstance being bold in 3, but it is also a usage of it, not it's declaration like in 2. Then, same thing at 4. Local variable are indistinguishable in declaration and uses.

A solution would be to introduce a new meta scope around all name introduction.

Today myVar at line 4 have those scopes:

  • meta.body.function.definition.cpp
  • meta.function.definition.cpp
  • source.cpp

And semantic token type variable with modifier local.

With my proposition, it would look like this:

  • meta.name-introduction.cpp
  • meta.body.function.definition.cpp
  • meta.function.definition.cpp
  • source.cpp

That meta scope would surround the name MyStruct in 1, the name myInstance in 2, the name function in 3 and the name myVar in 4.

That way, a color theme could highlight declaration and definition differently from uses of a name.

A name can be introduced multiple times. For example:

struct MyStruct;

struct MyStruct {
    auto fn() -> void;
};

auto MyStruct::fn() -> void {
   // ...
}

Here, both name have a declaration and a definition and no uses.

Contributor guide

Open the contributing guide

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 tracing how C++ declarations, definitions, and semantic token type variable with modifier local become TextMate scopes. Use the examples in the issue as cases, including struct names, variables, functions, and repeated declarations. Done means meta.name-introduction.cpp surrounds introductions without also matching ordinary uses.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.