microsoft / microsoft/language-server-protocol

new feature: describe (type of) selected expression

Open
#1,466 3 comments 8 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

When and reading and analyzing code, aside from navigating the reference graph, the most common need I encounter is to understand what the type is of a given expression. The expression needn't be a name; it could be a subexpression of a larger expression; and it could be either a type or a term.

In the Guru tool (an early "editor-agnostic code oracle" like an LSP server, but specific to Go), one could select any subexpression and learn immediately:

  • what it is (e.g. a call to a built-in function; a map index expression; etc)
  • where it is defined, if it is an identifier (overlapping functionality with "go to definition")
  • what is the underlying type of the selected expression, whether a term or type. In Go, this determines its representation and what operations are available.
  • the size and alignment of the type, in bytes. This is useful during performance optimization.
  • the set of fields and methods, expressed compactly one per line, with "inheritance" and embedding flattened out. This feature overlaps with completion, but completion is triggered by edits, whereas this information is useful during reading too.

You can see a short GIF animation of the feature here: http://golang.org/s/using-guru#heading=h.re7ifmz33xbj

LSP's existing operations don't seem to cover this set of features. The textDocument/hover request provides only a point in the code, not a selection, so it cannot identify a particular subexpression of interest. The textDocument/typeDefinition request also provides only a point, only works on named entities, and only traverses the type one step at a time, rather than reporting information about the flattened type and all its computed fields and methods.

Might it be worth adding an operation to the protocol that answers the question "what does this selection mean"?

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 textDocument/hover and textDocument/typeDefinition operations described in the issue, then compare their scope with the proposed selection-based query. Done means the protocol need and a concrete operation design are agreed, including how selected expressions and the requested type information are represented.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.