Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A consistent naming scheme for the LanguageService constructors , with backward compatibility functions. #473

Merged
merged 64 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
7791a57
renamed all language services towards consistency. All verbs or all n…
jurgenvinju Oct 11, 2024
0d86206
made plural/singular consistent
jurgenvinju Oct 11, 2024
31e9417
added missing renaming
jurgenvinju Oct 11, 2024
c926ef9
fixed errors detected by static checker
jurgenvinju Oct 11, 2024
d861a8d
more typos
jurgenvinju Oct 11, 2024
64f8804
fixes #472
jurgenvinju Oct 11, 2024
3d2ea0a
getting the names right
jurgenvinju Oct 11, 2024
5037798
removed superfluous documentation
jurgenvinju Oct 11, 2024
34a6481
more doc cleanup
jurgenvinju Oct 11, 2024
b8da753
Merge branch 'main' into more-consistent-service-names
jurgenvinju Oct 12, 2024
bed2e0e
aligned all the service names with their LSP sources, and extrapolate…
jurgenvinju Oct 12, 2024
71a8ad6
fixed reference to old name
jurgenvinju Oct 12, 2024
f946b1c
fixing minor issues and added demo of using the new API
jurgenvinju Oct 12, 2024
364c393
fixed issues in documentation
jurgenvinju Oct 13, 2024
0d995d5
fixed parse error
jurgenvinju Oct 13, 2024
1d19a4a
renamed constructor names of services in Java side
jurgenvinju Oct 13, 2024
33f86d1
better types for the picoActions function
jurgenvinju Oct 13, 2024
0f707cd
Merge branch 'main' into more-consistent-service-names
jurgenvinju Oct 13, 2024
5518859
Update rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc
jurgenvinju Oct 14, 2024
60f1754
fixes based on feedback by @sungshik and @davylandman, plus renamed S…
jurgenvinju Oct 14, 2024
cec6310
setting more things straight, especially in the example code
jurgenvinju Oct 14, 2024
50409fe
forgot to add
jurgenvinju Oct 14, 2024
87f09e6
added pitfall
jurgenvinju Oct 14, 2024
8820535
picoLanguageServer not Contribution
jurgenvinju Oct 14, 2024
21a080f
more documentation
jurgenvinju Oct 14, 2024
dfb0bc3
added field names for services back in du to bug in interpreter with …
jurgenvinju Oct 14, 2024
5c37e7a
renamed outline to DocumentSymbols for Rascal as well
jurgenvinju Oct 14, 2024
1c317c6
added backward compatibility wrapper for the Summary.documentation field
jurgenvinju Oct 15, 2024
ef7a3ff
fixed new broken links in docs
jurgenvinju Oct 15, 2024
5ecaff1
improved links in docs
jurgenvinju Oct 15, 2024
dded438
minor fix
jurgenvinju Oct 15, 2024
7c3b87a
improved documentation for compatibility layer
jurgenvinju Oct 15, 2024
ffb9e4f
fixed another typo
jurgenvinju Oct 15, 2024
09ae6d7
docs
jurgenvinju Oct 15, 2024
b22c854
added computeFocusList for testing purposes
jurgenvinju Oct 15, 2024
e80b8f1
fixed interface of computeFocusList
jurgenvinju Oct 15, 2024
c4a4204
log string improved
jurgenvinju Oct 16, 2024
f386f58
Rename methods in `ILanguageContributions` to be consistent with LSP
sungshik Oct 17, 2024
7e3968e
Revert "Rename methods in `ILanguageContributions` to be consistent w…
sungshik Oct 17, 2024
617731d
Rename methods in `ILanguageContributions` to be consistent with LSP
sungshik Oct 17, 2024
90eaac8
Rename methods in `LanguageContributionsMultiplexer` to be consistent…
sungshik Oct 17, 2024
231157d
Rename methods in `InterpretedLanguageContributions` to be consistent…
sungshik Oct 17, 2024
3aeef96
Fix flaky UI test
sungshik Oct 21, 2024
59e361e
Rename methods in `RascalADTs` to be consistent with LSP
sungshik Oct 21, 2024
89b10d6
Merge branch 'more-consistent-service-names-flaky-test' into more-con…
sungshik Oct 21, 2024
d1bd97d
Merge pull request #484 from usethesource/more-consistent-service-nam…
DavyLandman Oct 21, 2024
6b1418b
Rename methods in `RascalLanguageServices` to be consistent with LSP
sungshik Oct 21, 2024
7b3e7ac
Rename methods in `ParametricSummary` to be consistent with LSP
sungshik Oct 21, 2024
565b70a
Rename methods in `RascalTextDocumentService` to be consistent with LSP
sungshik Oct 21, 2024
0a54319
Rename methods in `ParametricTextDocumentService` to be consistent wi…
sungshik Oct 21, 2024
8951698
Rename methods in `Outline` to be consistent with LSP
sungshik Oct 21, 2024
8374e3b
Merge branch 'more-consistent-service-names' into more-consistent-ser…
sungshik Oct 21, 2024
33fa928
Rename method `hasCodeLensDetector` to be consistent with LSP (previo…
sungshik Oct 21, 2024
eae06cf
Improve code layout
sungshik Oct 21, 2024
c1b9dc5
Rename class `Outline` to `DocumentSymbols`
sungshik Oct 22, 2024
a583630
Made names shorter (without `run..Service` pre/suffix)
sungshik Oct 23, 2024
b8cdde6
Made names shorter (without `run..Service` pre/suffix)
sungshik Oct 23, 2024
16d87be
Remove horizontal alignment
sungshik Oct 23, 2024
6fdc985
Merge pull request #482 from usethesource/more-consistent-service-nam…
jurgenvinju Oct 23, 2024
b1b5466
renamed LanguageServer to OldStyleLanguageServer and NewLanguageServe…
jurgenvinju Oct 23, 2024
f059ed4
Merge branch 'main' into more-consistent-service-names
jurgenvinju Oct 23, 2024
3158b01
forgot to add
jurgenvinju Oct 23, 2024
fb9a22e
fixed module names in Language meta data
jurgenvinju Oct 23, 2024
4939d4b
fixed tutor links
jurgenvinju Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public class RascalADTs {
private RascalADTs() {}
public static class LanguageContributions {
private LanguageContributions () {}
public static final String PARSER = "parser";
public static final String ANALYZER = "analyzer";
public static final String BUILDER = "builder";
public static final String OUTLINER = "outliner";
public static final String PARSER = "parsing";
public static final String ANALYZER = "analysis";
public static final String BUILDER = "build";
public static final String OUTLINER = "documentSymbol";
public static final String LENS_DETECTOR = "lenses";
public static final String INLAY_HINTER = "inlayHinter";
public static final String COMMAND_EXECUTOR = "executor";
public static final String DOCUMENTER = "documenter";
public static final String DEFINER = "definer";
public static final String REFERRER = "referrer";
public static final String IMPLEMENTER = "implementer";
public static final String CODE_ACTION_CONTRIBUTOR = "actions";
public static final String INLAY_HINTER = "inlayHint";
public static final String COMMAND_EXECUTOR = "execution";
public static final String DOCUMENTER = "hover";
public static final String DEFINER = "definition";
public static final String REFERRER = "reference";
public static final String IMPLEMENTER = "implementation";
public static final String CODE_ACTION_CONTRIBUTOR = "codeAction";
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved

public static class Summarizers {
private Summarizers() {}
Expand Down
3 changes: 2 additions & 1 deletion rascal-lsp/src/main/rascal/demo/lang/pico/LanguageServer.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
}
// @deprecated{This demo has been superseded by ((NewLanguageServer)) which avoids the use of deprecated API.}
module demo::lang::pico::LanguageServer

import util::LanguageServer;
Expand Down Expand Up @@ -113,7 +114,7 @@ list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs)
= [action(title="Change to <existing<0>>", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs];

@synopsis{Finds a declaration that the cursor is on and proposes to remove it.}
list[CodeAction] picoActions([*_, IdType x, *_, start[Program] program])
list[CodeAction] picoActions([*Tree _, IdType x, *Tree _, start[Program] program])
= [action(command=removeDecl(program, x, title="remove <x>"))];

default list[CodeAction] picoActions(Focus _focus) = [];
Expand Down
187 changes: 187 additions & 0 deletions rascal-lsp/src/main/rascal/demo/lang/pico/NewLanguageServer.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
@license{
Copyright (c) 2018-2023, NWO-I CWI and Swat.engineering
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
}
module demo::lang::pico::NewLanguageServer
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved

import util::LanguageServer;
import util::IDEServices;
import ParseTree;
import util::Reflective;
import lang::pico::\syntax::Main;

@synopsis{Provides each contribution (IDE feature) as a callback element of the set of LanguageServices.}
set[LanguageService] picoLanguageContributor() = {
parsing(parser(#start[Program])),
documentSymbol(picoOutliner),
codeLense(picoLenses),
execution(picoCommands),
inlayHint(picoHinter),
definition(lookupDef),
codeAction(picoActions)
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved
};

@synopsis{This set of contributions runs slower but provides more detail.}
set[LanguageService] picoLanguageContributorSlowSummary() = {
parsing(parser(#start[Program])),
analysis(picoAnalyzer, providesImplementations = false),
build(picoBuilder)
};

@synopsis{The outliner maps pico syntax trees to lists of DocumentSymbols.}
list[DocumentSymbol] picoOutliner(start[Program] input)
= [symbol("<input.src>", DocumentSymbolKind::\file(), input.src, children=[
*[symbol("<var.id>", \variable(), var.src) | /IdType var := input]
])];

@synopsis{The analyzer maps pico syntax trees to error messages and references}
Summary picoAnalyzer(loc l, start[Program] input) = picoSummarizer(l, input, analyze());

@synopsis{The builder does a more thorough analysis then the analyzer, providing more detail}
Summary picoBuilder(loc l, start[Program] input) = picoSummarizer(l, input, build());

@synopsis{A simple "enum" data type for switching between analysis modes}
data PicoSummarizerMode
= analyze()
| build()
;

@synopsis{Translates a pico syntax tree to a model (Summary) of everything we need to know about the program in the IDE.}
Summary picoSummarizer(loc l, start[Program] input, PicoSummarizerMode mode) {
Summary s = summary(l);

// definitions of variables
rel[str, loc] defs = {<"<var.id>", var.src> | /IdType var := input};

// uses of identifiers
rel[loc, str] uses = {<id.src, "<id>"> | /Id id := input};

// documentation strings for identifier uses
rel[loc, str] docs = {<var.src, "*variable* <var>"> | /IdType var := input};

// Provide errors (cheap to compute) both in analyze mode and in build mode.
s.messages += {<src, error("<id> is not defined", src, fixes=prepareNotDefinedFixes(src, defs))>
| <src, id> <- uses, id notin defs<0>};

// "references" are links for loc to loc (from def to use)
s.references += (uses o defs)<1,0>;

// "definitions" are also links from loc to loc (from use to def)
s.definitions += uses o defs;

// "documentation" maps locations to strs
s.documentation += (uses o defs) o docs;

// Provide warnings (expensive to compute) only in build mode
if (build() := mode) {
rel[loc, str] asgn = {<id.src, "<id>"> | /Statement stmt := input, (Statement) `<Id id> := <Expression _>` := stmt};
s.messages += {<src, warning("<id> is not assigned", src)> | <id, src> <- defs, id notin asgn<1>};
}

return s;
}

@synopsis{Looks up the declaration for any variable use using a list match into a ((Focus))}
set[loc] lookupDef([*_, Id use, *_, start[Program] input]) = { def.src | /IdType def := input, use := def.id};

@synopsis{If a variable is not defined, we list a fix of fixes to replace it with a defined variable instead.}
list[CodeAction] prepareNotDefinedFixes(loc src, rel[str, loc] defs)
= [action(title="Change to <existing<0>>", edits=[changed(src.top, [replace(src, existing<0>)])]) | existing <- defs];

@synopsis{Finds a declaration that the cursor is on and proposes to remove it.}
list[CodeAction] picoActions([*_, IdType x, *_, start[Program] program])
= [action(command=removeDecl(program, x, title="remove <x>"))];

default list[CodeAction] picoActions(Focus _focus) = [];

@synsopsis{Defines three example commands that can be triggered by the user (from a code lens, from a diagnostic, or just from the cursor position)}
data Command
= renameAtoB(start[Program] program)
| removeDecl(start[Program] program, IdType toBeRemoved)
;

@synopsis{Adds an example lense to the entire program.}
lrel[loc,Command] picoLenses(start[Program] input)
= [<input@\loc, renameAtoB(input, title="Rename variables a to b.")>];

@synopsis{Generates inlay hints that explain the type of each variable usage.}
list[InlayHint] picoHinter(start[Program] input) {
typeLookup = ( "<name>" : "<tp>" | /(IdType)`<Id name> : <Type tp>` := input);

return [
hint(name.src, " : <typeLookup["<name>"]>", \type(), atEnd = true)
| /(Expression)`<Id name>` := input
, "<name>" in typeLookup
];
}

@synopsis{Helper function to generate actual edit actions for the renameAtoB command}
list[DocumentEdit] getAtoBEdits(start[Program] input)
= [changed(input@\loc.top, [replace(id@\loc, "b") | /id:(Id) `a` := input])];

@synopsis{Command handler for the renameAtoB command}
value picoCommands(renameAtoB(start[Program] input)) {
applyDocumentsEdits(getAtoBEdits(input));
return ("result": true);
}

@synopsis{Command handler for the removeDecl command}
value picoCommands(removeDecl(start[Program] program, IdType toBeRemoved)) {
applyDocumentsEdits([changed(program@\loc.top, [replace(toBeRemoved@\loc, "")])]);
return ("result": true);
}

@synopsis{The main function registers the Pico language with the IDE}
@description{
Register the Pico language and the contributions that supply the IDE with features.

((registerLanguage)) is called twice here:
1. first for fast and cheap contributions
2. asynchronously for the full monty that loads slower
}
@benefits{
* You can run each contribution on an example in the terminal to test it first.
Any feedback (errors and exceptions) is faster and more clearly printed in the terminal.
}
void main() {
registerLanguage(
language(
pathConfig(),
"Pico",
{"pico", "pico-new"},
"demo::lang::pico::LanguageServer",
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved
"picoLanguageContributor"
)
);
registerLanguage(
language(
pathConfig(),
"Pico",
{"pico", "pico-new"},
"demo::lang::pico::LanguageServer",
jurgenvinju marked this conversation as resolved.
Show resolved Hide resolved
"picoLanguageContributorSlowSummary"
)
);
}
Loading
Loading