Skip to content

Commit 31a4d55

Browse files
committed
Reorganize LSP server, tidy
1 parent 8901f69 commit 31a4d55

File tree

4 files changed

+38
-157
lines changed

4 files changed

+38
-157
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Jérémy Faivre
3+
Copyright (c) 2025 Jérémy Faivre
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Persistent state remains throughout your story:
137137

138138
```lor
139139
state
140-
coffeeBeans: 100 // Track inventory
140+
coffeeBeans: 100 // Track inventory
141141
rushHour: false // Is it busy?
142142
dayNumber: 1 // Which day of the story
143143
```
@@ -304,13 +304,9 @@ Happy writing!
304304

305305
Loreline scripts are written in `.lor` files. See [CoffeeShop.lor](/test/CoffeeShop.lor) and [Minimal.lor](/test/Minimal.lor) as examples.
306306

307-
You can write these with any text editor, but the best option is using [Visual Studio Code](https://code.visualstudio.com/) along with the [Loreline Extension](https://marketplace.visualstudio.com/items?itemName=jeremyfa.loreline). This will make your editor support syntax highlighting of `.lor` files, which makes the content much more readable and easy to work with:
307+
You can write these with any text editor, but the best option available for free is using [Visual Studio Code](https://code.visualstudio.com/) along with the [Loreline Extension](https://marketplace.visualstudio.com/items?itemName=jeremyfa.loreline). This will make your editor support syntax highlighting of `.lor` files, which makes the content much more readable and easy to work with:
308308

309-
![Minimal example, syntax highlighted in VSCode](/minimal-screenshot.png)
310-
311-
It will also provide code completion and additional info from your script:
312-
313-
![Example of Hover information in VSCode](/hover-screenshot.png)
309+
![Screenshot of the Loreline extension for VSCode](/vscode-screenshot.png)
314310

315311
## Test using the command line interface
316312

hover-screenshot.png

-158 KB
Binary file not shown.

src/loreline/lsp/Server.hx

+34-149
Original file line numberDiff line numberDiff line change
@@ -170,43 +170,7 @@ class Server {
170170
throw { code: ErrorCodes.ServerNotInitialized, message: "Server not initialized" };
171171
}
172172

173-
final result = switch (request.method) {
174-
case "initialize":
175-
handleInitialize(cast request.params);
176-
177-
case "shutdown":
178-
handleShutdown();
179-
180-
case "textDocument/completion":
181-
handleCompletion(cast request.params);
182-
183-
case "textDocument/definition":
184-
handleDefinition(cast request.params);
185-
186-
case "textDocument/hover":
187-
handleHover(cast request.params);
188-
189-
case "textDocument/documentSymbol":
190-
handleDocumentSymbol(cast request.params);
191-
192-
case "textDocument/references":
193-
null;
194-
// TODO
195-
//handleReferences(cast request.params);
196-
197-
case "textDocument/formatting":
198-
handleDocumentFormatting(cast request.params);
199-
200-
case "loreline/documentChoiceOptions":
201-
handleDocumentChoiceOptions(cast request.params);
202-
203-
case "loreline/documentTextStatements":
204-
handleDocumentTextStatements(cast request.params);
205-
206-
case _:
207-
throw { code: ErrorCodes.MethodNotFound, message: 'Method not found: ${request.method}'};
208-
}
209-
173+
final result = resolveRequest(request);
210174
return createResponse(request.id, result);
211175

212176
} catch (e:Any) {
@@ -221,6 +185,39 @@ class Server {
221185
return null;
222186
}
223187

188+
function resolveRequest(request:RequestMessage):Any {
189+
190+
return switch (request.method) {
191+
case "initialize":
192+
handleInitialize(cast request.params);
193+
194+
case "shutdown":
195+
handleShutdown();
196+
197+
case "textDocument/completion":
198+
handleCompletion(cast request.params);
199+
200+
case "textDocument/definition":
201+
handleDefinition(cast request.params);
202+
203+
case "textDocument/hover":
204+
handleHover(cast request.params);
205+
206+
case "textDocument/documentSymbol":
207+
handleDocumentSymbol(cast request.params);
208+
209+
case "textDocument/references":
210+
null; // TODO
211+
212+
case "textDocument/formatting":
213+
handleDocumentFormatting(cast request.params);
214+
215+
case _:
216+
throw { code: ErrorCodes.MethodNotFound, message: 'Method not found: ${request.method}'};
217+
}
218+
219+
}
220+
224221
/**
225222
* Handle a notification message
226223
*/
@@ -1984,118 +1981,6 @@ class Server {
19841981
return [];
19851982
}
19861983

1987-
function handleDocumentChoiceOptions(params:{
1988-
textDocument:TextDocumentIdentifier
1989-
}):Array<{kind:String, range:loreline.lsp.Protocol.Range}> {
1990-
1991-
final ast = documents.get(params.textDocument.uri);
1992-
if (ast == null) return [];
1993-
1994-
final content = documentContents.get(params.textDocument.uri);
1995-
1996-
final result = [];
1997-
1998-
ast.eachExcludingImported((node, parent) -> {
1999-
if (node is NChoiceOption) {
2000-
final opt:NChoiceOption = cast node;
2001-
result.push({
2002-
kind: 'option',
2003-
range: rangeFromLorelinePosition(opt.text.pos, content)
2004-
});
2005-
2006-
if (opt.text != null) {
2007-
if (opt.text.quotes == DoubleQuotes) {
2008-
result.push({
2009-
kind: 'text',
2010-
range: rangeFromLorelinePosition(new loreline.Position(
2011-
opt.text.pos.line,
2012-
opt.text.pos.column,
2013-
opt.text.pos.offset,
2014-
1
2015-
), content)
2016-
});
2017-
}
2018-
for (part in opt.text.parts) {
2019-
switch part.partType {
2020-
case Raw(text):
2021-
result.push({
2022-
kind: 'text',
2023-
range: rangeFromLorelinePosition(part.pos, content)
2024-
});
2025-
case _:
2026-
}
2027-
}
2028-
if (opt.text.quotes == DoubleQuotes) {
2029-
result.push({
2030-
kind: 'text',
2031-
range: rangeFromLorelinePosition(opt.text.pos.withOffset(content, opt.text.pos.length - 1, 1), content)
2032-
});
2033-
}
2034-
}
2035-
}
2036-
});
2037-
2038-
return result;
2039-
2040-
}
2041-
2042-
function handleDocumentTextStatements(params:{
2043-
textDocument:TextDocumentIdentifier
2044-
}):Array<{kind:String, range:loreline.lsp.Protocol.Range}> {
2045-
2046-
final ast = documents.get(params.textDocument.uri);
2047-
if (ast == null) return [];
2048-
2049-
final content = documentContents.get(params.textDocument.uri);
2050-
2051-
final result = [];
2052-
2053-
ast.eachExcludingImported((node, parent) -> {
2054-
if (node is NTextStatement) {
2055-
final text:NTextStatement = cast node;
2056-
result.push({
2057-
kind: 'statement',
2058-
range: rangeFromLorelinePosition(text.pos, content)
2059-
});
2060-
2061-
if (text.content != null) {
2062-
if (text.content.quotes == DoubleQuotes) {
2063-
result.push({
2064-
kind: 'text',
2065-
range: rangeFromLorelinePosition(new loreline.Position(
2066-
text.content.pos.line,
2067-
text.content.pos.column,
2068-
text.content.pos.offset,
2069-
1
2070-
), content)
2071-
});
2072-
}
2073-
for (part in text.content.parts) {
2074-
switch part.partType {
2075-
case Raw(text):
2076-
for (sub in extractTextSectionsExcludingComments(text)) {
2077-
result.push({
2078-
kind: 'text',
2079-
range: rangeFromLorelinePosition(part.pos.withOffset(content, sub.offset, sub.length), content)
2080-
});
2081-
}
2082-
case _:
2083-
}
2084-
}
2085-
if (text.content.quotes == DoubleQuotes) {
2086-
result.push({
2087-
kind: 'text',
2088-
range: rangeFromLorelinePosition(text.content.pos.withOffset(content, text.content.pos.length - 1, 1), content)
2089-
});
2090-
}
2091-
}
2092-
}
2093-
});
2094-
2095-
return result;
2096-
2097-
}
2098-
20991984
function extractTextSectionsExcludingComments(text:String):Array<{offset:Int, length:Int}> {
21001985
final results:Array<{offset:Int, length:Int}> = [];
21011986

0 commit comments

Comments
 (0)