-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
424: New features to LSP r=ice1000 a=imkiva this PR upgraded LSP4j to 0.14 with inlay hints support; added some features to the LSP backend: - Inlay type hints for bind patterns (feel free to suggest more) - CodeLens of each definition showing `%d usages` - Code folding for definitions that occupy 3 or more LOC. - Search Everywhere in VSCode (symbols only since VSC does not ask more from backend) Try it: https://github.com/aya-prover/aya-vscode/suites/6895435995/artifacts/267446633 ## See also Language Server Protocol has recently upgraded to 3.17, and VSCode stabilized their inlay hints APIs - https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint - rust-lang/rust-analyzer#11445 - microsoft/vscode-languageserver-node#495 - aya-prover/aya-vscode#21 Co-authored-by: imkiva <imkiva@islovely.icu>
- Loading branch information
Showing
32 changed files
with
499 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2020-2022 Yinsen (Tesla) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.lsp.actions; | ||
|
||
import kala.collection.mutable.MutableList; | ||
import org.aya.cli.library.source.LibrarySource; | ||
import org.aya.concrete.stmt.Command; | ||
import org.aya.concrete.stmt.Decl; | ||
import org.aya.lsp.utils.LspRange; | ||
import org.aya.lsp.utils.Resolver; | ||
import org.aya.util.error.SourcePos; | ||
import org.eclipse.lsp4j.FoldingRange; | ||
import org.eclipse.lsp4j.FoldingRangeKind; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public final class Folding implements SyntaxDeclAction<@NotNull MutableList<FoldingRange>> { | ||
public static @NotNull List<FoldingRange> invoke(@NotNull LibrarySource source) { | ||
var ranges = MutableList.<FoldingRange>create(); | ||
var folder = new Folding(); | ||
var program = source.program().value; | ||
if (program != null) program.forEach(decl -> folder.visit(decl, ranges)); | ||
return ranges.asJava(); | ||
} | ||
|
||
@Override | ||
public void visitCommand(@NotNull Command cmd, @NotNull MutableList<FoldingRange> pp) { | ||
if (cmd instanceof Command.Module mod) pp.append(toFoldingRange(mod.entireSourcePos())); | ||
SyntaxDeclAction.super.visitCommand(cmd, pp); | ||
} | ||
|
||
@Override public void visitDecl(@NotNull Decl maybe, @NotNull MutableList<FoldingRange> pp) { | ||
Resolver.withChildren(maybe).filter(dv -> dv.concrete != null) | ||
.map(dv -> dv.concrete.entireSourcePos()) | ||
.filter(pos -> pos.linesOfCode() >= 3) | ||
.forEach(pos -> pp.append(toFoldingRange(pos))); | ||
SyntaxDeclAction.super.visitDecl(maybe, pp); | ||
} | ||
|
||
private @NotNull FoldingRange toFoldingRange(@NotNull SourcePos sourcePos) { | ||
var range = LspRange.toRange(sourcePos); | ||
var fr = new FoldingRange(range.getStart().getLine(), range.getEnd().getLine()); | ||
fr.setStartCharacter(range.getStart().getCharacter()); | ||
fr.setEndCharacter(range.getEnd().getCharacter()); | ||
fr.setKind(FoldingRangeKind.Region); | ||
return fr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2020-2022 Yinsen (Tesla) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.lsp.actions; | ||
|
||
import kala.collection.mutable.MutableList; | ||
import org.aya.cli.library.source.LibrarySource; | ||
import org.aya.concrete.Pattern; | ||
import org.aya.lsp.utils.LspRange; | ||
import org.aya.lsp.utils.XYXY; | ||
import org.aya.util.distill.DistillerOptions; | ||
import org.eclipse.lsp4j.InlayHint; | ||
import org.eclipse.lsp4j.InlayHintKind; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public record InlayHintMaker(@NotNull MutableList<InlayHint> hints) implements SyntaxNodeAction.Ranged { | ||
public static @NotNull List<InlayHint> invoke(@NotNull LibrarySource source, @NotNull Range range) { | ||
var program = source.program().value; | ||
if (program == null) return Collections.emptyList(); | ||
var xyxy = new XYXY(range); | ||
var maker = new InlayHintMaker(MutableList.create()); | ||
maker.visitAll(program, xyxy); | ||
return maker.hints.asJava(); | ||
} | ||
|
||
@Override public @NotNull Pattern visitPattern(@NotNull Pattern pattern, XYXY pp) { | ||
if (pattern instanceof Pattern.Bind bind && bind.type().value != null) { | ||
var type = bind.type().value.toDoc(DistillerOptions.pretty()).commonRender(); | ||
var range = LspRange.toRange(bind.sourcePos()); | ||
var hint = new InlayHint(range.getEnd(), Either.forLeft(": " + type)); | ||
hint.setKind(InlayHintKind.Type); | ||
hint.setPaddingLeft(true); | ||
hints.append(hint); | ||
} | ||
return Ranged.super.visitPattern(pattern, pp); | ||
} | ||
} |
Oops, something went wrong.