microsoft / microsoft/language-server-protocol

[Proposal] Pipeline hints

Open
#2,074 3 comments 4 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

Pipeline hints

Problem

F#, and I'm sure other languages, heavily utilizes pipelining/chaining of function calls. Such pipelines can at times make knowing types quite difficult, particularly if you're unfamiliar with the domain.

F#

let input = System.IO.File.ReadAllLines("day1.txt")

input
|> Array.map Utils.splitStringIntoPair
|> Array.map Utils.convertStringPairToIntPair
|> Array.unzip
|> Utils.sortTupleElements
|-> Array.zip
|> Array.map Utils.abs
|> Array.sum
|> Taps.logAndContinue "Part 1: %d"

Fluent APIs have become much more common lately, with things like Zod being used in the JavaScript ecosystem for typesafe validation, and ASP.Net Core utilizing it heavily with their entrypoint file, the need for IntelliSense on these implicit return types are becoming increasingly more common.

C#

WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
builder.Services
    .AddSingleton<TimeProvider>(TimeProvider.System)
    .AddScoped<IPersonService, PersonService>()

WebApplication app = builder.Build();

app
    .MapGet("/api/person/{id}" (Guid id) => { /* Logic here */  })
    .WithDescription("Retrieves the person with the given id")

app.Run();

Proposal

I'm suggesting a new request designed to highlight return types of function calls whose values are implicitly passed to another function. This will help solve both of the previous problem statements.

I am not well versed enough in the intricate details of the LSP request specification to come up with anything more detailed than these visual examples, so at the moment I'm mostly interrested in starting a discussion; The request specification can come at a later date.

(Imagine that the code in the comments are the hints provided by the LSP, and not code comments)

F#

let input = System.IO.File.ReadAllLines("day1.txt")

input
|> Array.map Utils.splitStringIntoPair // (string * string) array
|> Array.map Utils.convertStringPairToIntPair // (int * int) array
|> Array.unzip // (int array) * (int array)
|> Utils.sortTupleElements // (int array) * (int array)
|-> Array.zip // (int * int) array
|> Array.map Utils.abs // int array
|> Array.sum // int
|> Taps.logAndContinue "Part 1: %d" // int

C#

WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
builder.Services
    .AddSingleton<TimeProvider>(TimeProvider.System) // IServiceCollection
    .AddScoped<IPersonService, PersonService>() // IServiceCollection

WebApplication app = builder.Build();

app
    .MapGet("/api/person/{id}" (Guid id) => { /* Logic here */  }) // RouteHandlerBuilder
    .WithDescription("Retrieves the person with the given id") // RouteHandlerBuilder

app.Run();

Alternatives

Extend the existing inlayHints request instead of creating a new one. This has the advantage of not requiring an entirely new request type, but the downside of polluting the inlayHints request, as well as any possible breaking changes to make it more ergonomic for this need.

Potentially relevant information

The naming is based off of Ionide (The F# LSP), which has their own custom fsharp-specific request with the same name, and has implemented it in their Visual Studio Code Plugin, but has not done so in their Neovim plugin, due to lack of support in Neovim.

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

Read the existing inlayHints request specification first, then compare Ionide's custom F# pipeline-hints request and the linked VS Code and Neovim discussions. Done would require an agreed request design and specification, including whether this belongs in inlayHints or as a new request type.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, fsharp
Domain
api, 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.