Skip to content

Commit 2bf16de

Browse files
committed
Update call hierarchy API + example.
1 parent e4ad1e5 commit 2bf16de

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

rascal-lsp/src/main/rascal/library/demo/lang/pico/LanguageServer.rsc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ import util::IDEServices;
3838
import ParseTree;
3939
import util::ParseErrorRecovery;
4040
import util::Reflective;
41-
import lang::pico::\syntax::Main;
41+
extend lang::pico::\syntax::Main;
42+
43+
syntax IdType
44+
= func: Type returnType Id id "(" {IdType ","}* params ")" "=" Expression body ";"
45+
;
46+
47+
syntax Expression
48+
= call: Id id "(" {Expression ","}* args ")"
49+
;
4250

4351
private Tree (str _input, loc _origin) picoParser(bool allowRecovery) {
4452
return ParseTree::parser(#start[Program], allowRecovery=allowRecovery, filters=allowRecovery ? {createParseErrorFilter(false)} : {});
@@ -57,7 +65,10 @@ set[LanguageService] picoLanguageServer(bool allowRecovery) = {
5765
execution(picoExecutionService),
5866
inlayHint(picoInlayHintService),
5967
definition(picoDefinitionService),
60-
codeAction(picoCodeActionService)
68+
codeAction(picoCodeActionService),
69+
callHierarchy(picoCallHierarchyService),
70+
incomingCalls(picoIncomingCallsService),
71+
outgoingCalls(picoOutgoingCallsService)
6172
};
6273

6374
set[LanguageService] picoLanguageServer() = picoLanguageServer(false);
@@ -188,6 +199,18 @@ value picoExecutionService(removeDecl(start[Program] program, IdType toBeRemoved
188199
return ("result": true);
189200
}
190201
202+
set[CallHierarchyItem] picoCallHierarchyService(Focus _:[*_, call:(Expression) `<Id id>(<{Expression ","}* _>)`, *_])
203+
= {item("<id>", function(), call@\loc)};
204+
205+
default set[CallHierarchyItem] picoCallHierarchyService(Focus _)
206+
= {};
207+
208+
set[loc] picoIncomingCallsService(Focus focus:[(Expression) `<Id defId>(<{Expression ","}* _>)`, *_], value _)
209+
= {call@\loc | /call:(Expression) `<Id callId>(<{Expression ","}* _>)` := focus[-1], "<defId>" == "<callId>"};
210+
211+
set[loc] picoOutgoingCallsService(Focus focus:[(Expression) `<Id defId>(<{Expression ","}* _>)`, *_], value _)
212+
= {call@\loc | /call:(Expression) `<Id callId>(<{Expression ","}* _>)` := focus[-1], "<defId>" == "<callId>"};
213+
191214
@synopsis{The main function registers the Pico language with the IDE}
192215
@description{
193216
Register the Pico language and the contributions that supply the IDE with features.

rascal-lsp/src/main/rascal/library/util/LanguageServer.rsc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,16 @@ data LanguageService
269269
| implementation(set[loc] (Focus _focus) implementationService)
270270
| codeAction (list[CodeAction] (Focus _focus) codeActionService)
271271
| callHierarchy (set[CallHierarchyItem] (Focus _focus) callHierarchyService)
272-
| incomingCalls (set[loc] (loc src, value _data) incomingCallsService)
273-
| outgoingCalls (set[loc] (loc src, value _data) outgoingCallsService)
272+
| incomingCalls (set[loc] (Focus focus, value _data) incomingCallsService)
273+
| outgoingCalls (set[loc] (Focus focus, value _data) outgoingCallsService)
274274
;
275275

276276
data CallHierarchyItem
277277
= item(
278278
str name,
279279
DocumentSymbolKind kind,
280280
loc src,
281-
loc selection,
281+
loc selection = src,
282282
list[DocumentSymbolTag] tags = [],
283283
str detail = "",
284284
value \data = ()

0 commit comments

Comments
 (0)