@@ -5,7 +5,7 @@ import effekt.core.PrettyPrinter
5
5
import effekt .source .{ FunDef , Hole , ModuleDecl , Tree }
6
6
import effekt .util .{ PlainMessaging , getOrElseAborting }
7
7
import effekt .util .messages .EffektError
8
- import kiama .util .{ Filenames , Notebook , NotebookCell , Position , Services , Source }
8
+ import kiama .util .{ Filenames , Notebook , NotebookCell , Position , Services , Source , Range }
9
9
import kiama .output .PrettyPrinterTypes .Document
10
10
import org .eclipse .lsp4j .{ Diagnostic , DocumentSymbol , ExecuteCommandParams , SymbolKind }
11
11
@@ -30,7 +30,7 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
30
30
diagnostic(message.range, lspMessaging.formatContent(message), message.severity)
31
31
32
32
override def getDefinition (position : Position ): Option [Tree ] =
33
- getDefinitionAt(position)(context)
33
+ getDefinitionAt(position)(using context)
34
34
35
35
/**
36
36
* Overriding hook to also publish core and target for LSP server
@@ -83,14 +83,14 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
83
83
getSymbolHover(position) orElse getHoleHover(position)
84
84
85
85
def getSymbolHover (position : Position ): Option [String ] = for {
86
- (tree, sym) <- getSymbolAt(position)(context)
87
- info <- getInfoOf(sym)(context)
86
+ (tree, sym) <- getSymbolAt(position)(using context)
87
+ info <- getInfoOf(sym)(using context)
88
88
} yield if (settingBool(" showExplanations" )) info.fullDescription else info.shortDescription
89
89
90
90
def getHoleHover (position : Position ): Option [String ] = for {
91
- trees <- getTreesAt(position)(context)
91
+ trees <- getTreesAt(position)(using context)
92
92
tree <- trees.collectFirst { case h : source.Hole => h }
93
- info <- getHoleInfo(tree)(context)
93
+ info <- getHoleInfo(tree)(using context)
94
94
} yield info
95
95
96
96
def positionToLocation (p : Position ): Location = {
@@ -115,17 +115,26 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
115
115
id <- context.definitionTreeOption(sym)
116
116
decl <- getSourceTreeFor(sym)
117
117
kind <- getSymbolKind(sym)
118
- detail <- getInfoOf(sym)(context)
118
+ detail <- getInfoOf(sym)(using context)
119
119
} yield new DocumentSymbol (sym.name.name, kind, rangeOfNode(decl), rangeOfNode(id), detail.header)
120
120
Some (documentSymbols)
121
121
122
122
override def getReferences (position : Position , includeDecl : Boolean ): Option [Vector [Tree ]] =
123
123
for {
124
- (tree, sym) <- getSymbolAt(position)(context)
124
+ (tree, sym) <- getSymbolAt(position)(using context)
125
125
refs = context.distinctReferencesTo(sym)
126
126
allRefs = if (includeDecl) tree :: refs else refs
127
127
} yield allRefs.toVector
128
128
129
+ override def getInlayHints (range : kiama.util.Range ): Option [Vector [InlayHint ]] =
130
+ val captures = getInferredCaptures(range)(using context).map {
131
+ case (p, c) =>
132
+ val prettyCaptures = TypePrinter .show(c)
133
+ InlayHint (InlayHintKind .Type , p, prettyCaptures, markdownTooltip = s " captures: ` ${prettyCaptures}` " , paddingRight = true , effektKind = " capture" )
134
+ }.toVector
135
+
136
+ if captures.isEmpty then None else Some (captures)
137
+
129
138
// settings might be null
130
139
override def setSettings (settings : Object ): Unit = {
131
140
import com .google .gson .JsonObject
@@ -153,11 +162,11 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
153
162
154
163
override def getCodeActions (position : Position ): Option [Vector [TreeAction ]] =
155
164
Some (for {
156
- trees <- getTreesAt(position)(context).toVector
157
- actions <- trees.flatMap { t => action(t)(context) }
165
+ trees <- getTreesAt(position)(using context).toVector
166
+ actions <- trees.flatMap { t => action(t)(using context) }
158
167
} yield actions)
159
168
160
- def action (tree : Tree )(implicit C : Context ): Option [TreeAction ] = tree match {
169
+ def action (tree : Tree )(using C : Context ): Option [TreeAction ] = tree match {
161
170
case f : FunDef => inferEffectsAction(f)
162
171
case h : Hole => closeHoleAction(h)
163
172
case _ => None
@@ -213,18 +222,6 @@ trait LSPServer extends kiama.util.Server[Tree, EffektConfig, EffektError] with
213
222
tpe1 != tpe2 || effs1 != effs2
214
223
}
215
224
216
- case class CaptureInfo (location : Location , captureText : String )
217
-
218
- override def executeCommand (src : Source , params : ExecuteCommandParams ): Option [Any ] =
219
- if (params.getCommand == " inferredCaptures" ) {
220
- val captures = getInferredCaptures(src)(using context).map {
221
- case (p, c) => CaptureInfo (positionToLocation(p), TypePrinter .show(c))
222
- }
223
- if (captures.isEmpty) None else Some (captures.toArray)
224
- } else {
225
- None
226
- }
227
-
228
225
override def createServices (config : EffektConfig ) = new LSPServices (this , config)
229
226
230
227
// Class to easily test custom LSP services not (yet) meant to go into kiama.Services
0 commit comments