Skip to content

Commit 128a4da

Browse files
authored
Library updates / support Native (#3)
* Library updates / prep for Native * Use langoustine-app * unused import got broken ;)
1 parent 46f4934 commit 128a4da

4 files changed

Lines changed: 54 additions & 64 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

LSP.scala

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,33 @@ import fs2.io.file.Path
99
import cats.parse.Parser
1010
import QuickmaffsCompiler.CompileError
1111
import QuickmaffsCompiler.Index
12-
import langoustine.lsp.RuntimeBase.DocumentUri
13-
import langoustine.lsp.RuntimeBase.uinteger
12+
import langoustine.lsp.runtime.DocumentUri
13+
import langoustine.lsp.runtime.Opt
14+
import langoustine.lsp.runtime.uinteger
1415

1516
import cats.syntax.all.*
17+
import langoustine.lsp.app.LangoustineApp
1618

17-
object LSP extends IOApp.Simple:
19+
object LSP extends LangoustineApp:
1820
import QuickmaffsLSP.{server, State}
1921

20-
def run =
21-
FS2Channel[IO](2048, None)
22-
.evalTap { channel =>
23-
IO.ref(Map.empty[DocumentUri, State])
24-
.flatMap { state =>
25-
server(state).bind(channel)
26-
}
22+
def server(
23+
args: List[String]
24+
): Resource[cats.effect.IO, LSPBuilder[cats.effect.IO]] =
25+
Resource
26+
.eval(IO.ref(Map.empty[DocumentUri, State]))
27+
.map { state =>
28+
QuickmaffsLSP.server(state)
2729
}
28-
.flatMap(channel =>
29-
fs2.Stream
30-
.eval(IO.never) // running the server forever
31-
.concurrently(
32-
fs2.io
33-
.stdin[IO](512)
34-
.through(lsp.decodePayloads)
35-
.through(channel.input)
36-
)
37-
.concurrently(
38-
channel.output
39-
.through(lsp.encodePayloads)
40-
.through(fs2.io.stdout[IO])
41-
)
42-
)
43-
.compile
44-
.drain
45-
.guarantee(IO.consoleForIO.errorln("Terminating server"))
46-
end run
30+
.onFinalize(IO.consoleForIO.errorln("Terminating server"))
4731

4832
end LSP
4933

5034
object QuickmaffsLSP:
5135
import requests.*
52-
import structures.*
5336
import aliases.*
5437
import enumerations.*
55-
import json.*
38+
import structures.*
5639

5740
enum State:
5841
case Empty
@@ -68,7 +51,7 @@ object QuickmaffsLSP:
6851

6952
extension (s: cats.parse.Caret)
7053
def toPosition: Position =
71-
Position(line = uinteger(s.line), character = uinteger(s.col))
54+
Position(line = s.line, character = s.col)
7255

7356
extension (s: Span)
7457
def toRange: Range = Range(s.from.toPosition, s.to.toPosition)
@@ -143,7 +126,7 @@ object QuickmaffsLSP:
143126
)
144127
)
145128
case State.RuntimeError(err) =>
146-
val zero = uinteger(0)
129+
val zero = 0
147130
publish(
148131
Vector(
149132
Diagnostic(
@@ -210,9 +193,13 @@ object QuickmaffsLSP:
210193
foundMaybe
211194
.map(_._2)
212195
.map { vdf =>
213-
Definition(Location(in.textDocument.uri, vdf.definedAt.toRange))
196+
Opt(
197+
Definition(
198+
Location(in.textDocument.uri, vdf.definedAt.toRange)
199+
)
200+
)
214201
}
215-
.getOrElse(null)
202+
.getOrElse(Opt.empty)
216203
}
217204
}
218205
.handleRequest(textDocument.hover) { (in, back) =>
@@ -229,39 +216,42 @@ object QuickmaffsLSP:
229216
vdf.fullDefinition.to.offset
230217
)
231218

232-
Nullable {
219+
Opt {
233220
Hover(
234221
MarkupContent(
235222
kind = MarkupKind.Markdown,
236223
s"""
237-
|`$varName`
238-
|---
239-
|
240-
|**Value**: $value
241-
|
242-
|**Formula**: $text
243-
""".stripMargin.trim
224+
|`$varName`
225+
|---
226+
|
227+
|**Value**: $value
228+
|
229+
|**Formula**: $text
230+
""".stripMargin.trim
244231
)
245232
)
246233
}
247234
}
248-
.getOrElse(Nullable.NULL)
235+
.getOrElse(Opt.empty)
249236

250-
case _ => Nullable.NULL
237+
case _ => Opt.empty
251238
}
252239
}
253240
.handleRequest(textDocument.documentSymbol) { (in, back) =>
254241
get(in.textDocument.uri).map {
255242
case Some(State.Ok(idx, _, _)) =>
256-
idx.variables.toVector.sortBy(_._1).map { case (n, df) =>
257-
SymbolInformation(
258-
location = Location(in.textDocument.uri, df.definedAt.toRange),
259-
name = n,
260-
kind = enumerations.SymbolKind.Variable
261-
)
243+
Opt {
244+
idx.variables.toVector.sortBy(_._1).map { case (n, df) =>
245+
SymbolInformation(
246+
location =
247+
Location(in.textDocument.uri, df.definedAt.toRange),
248+
name = n,
249+
kind = enumerations.SymbolKind.Variable
250+
)
251+
}
262252
}
263253

264-
case _ => Vector.empty
254+
case _ => Opt(Vector.empty)
265255
}
266256
}
267257
.handleRequest(textDocument.rename) { (in, back) =>
@@ -273,7 +263,7 @@ object QuickmaffsLSP:
273263
TextEdit(range = span.toRange, newText = in.newName)
274264
}
275265

276-
Nullable {
266+
Opt {
277267
WorkspaceEdit(
278268
changes = Opt(
279269
Map(
@@ -283,7 +273,7 @@ object QuickmaffsLSP:
283273
)
284274
}
285275
}
286-
.getOrElse(Nullable.NULL)
276+
.getOrElse(Opt.empty)
287277
}
288278
}
289279
end server

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ clean:
66

77
bin/repl:
88
mkdir -p bin
9-
scala-cli package . -M REPL -f -o bin/repl
9+
scala-cli package . --main-class REPL --force --output bin/repl
1010

1111
bin/lsp:
1212
mkdir -p bin
13-
scala-cli package . -M LSP -f -o bin/lsp
13+
scala-cli package . --main-class LSP --force --output bin/lsp
1414

1515
bin/quickmaffs:
1616
mkdir -p bin
17-
scala-cli package . -M INTERPRETER -f -o bin/quickmaffs
17+
scala-cli package . --main-class INTERPRETER --force --output bin/quickmaffs
1818

19-
repl: bin/repl
20-
lsp: bin/lsp
21-
interpreter: bin/quickmaffs
19+
repl: bin/repl
20+
lsp: bin/lsp
21+
interpreter: bin/quickmaffs
2222

build.dependencies.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//> using lib "tech.neander::langoustine-lsp::0.0.7"
2-
//> using lib "tech.neander::jsonrpclib-fs2::0.0.3"
3-
//> using lib "co.fs2::fs2-io::3.2.11"
4-
//> using scala "3.1.3"
1+
//> using lib "tech.neander::langoustine-app::0.0.17"
2+
//> using lib "co.fs2::fs2-io::3.3.0"
3+
//> using scala "3.2.0"
54
//> using lib "org.typelevel::cats-parse::0.3.8"

0 commit comments

Comments
 (0)