Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
319 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ template/save | |
android/libs | ||
.vscode | ||
save | ||
*.log | ||
|
||
## Java | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> | ||
<fileset name="all" enabled="true" check-config-name="NVList" local="false"> | ||
<file-match-pattern match-pattern="." include-pattern="true"/> | ||
</fileset> | ||
</fileset-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
plugins { | ||
id 'java-library' | ||
id 'application' | ||
id 'maven-publish' | ||
id 'com.github.johnrengelman.shadow' | ||
} | ||
|
||
mainClassName = "nl.weeaboo.vn.langserver.LangServerMain" | ||
|
||
dependencies { | ||
implementation project(':nvlist-core') | ||
implementation deps.lsp4j | ||
|
||
runtimeOnly deps.slf4j_desktop | ||
} | ||
|
||
run { | ||
standardInput = System.in | ||
} | ||
|
||
tasks.register('runLangServer') { | ||
dependsOn 'run' | ||
} | ||
|
||
shadowJar { | ||
baseName = 'nvlist-langserver' | ||
classifier = null | ||
version = null | ||
} | ||
|
||
publishing { | ||
publications { | ||
langserver(MavenPublication) { | ||
from components.java | ||
artifactId 'nvlist-langserver' | ||
|
||
pom.withXml { | ||
asNode().children().last() + pomLicenseConfig | ||
} | ||
} | ||
} | ||
} | ||
|
||
bintray { | ||
publications = ['langserver'] | ||
} |
15 changes: 15 additions & 0 deletions
15
langserver/src/main/java/nl/weeaboo/vn/langserver/LangServerMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nl.weeaboo.vn.langserver; | ||
|
||
import java.io.IOException; | ||
|
||
import nl.weeaboo.vn.impl.InitConfig; | ||
|
||
final class LangServerMain { | ||
|
||
public static void main(String[] args) throws IOException { | ||
InitConfig.init(); | ||
|
||
NvlistLangServer.start(System.in, System.out); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
langserver/src/main/java/nl/weeaboo/vn/langserver/NvlistLangServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package nl.weeaboo.vn.langserver; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.PrintWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Future; | ||
|
||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.eclipse.lsp4j.InitializeResult; | ||
import org.eclipse.lsp4j.ServerCapabilities; | ||
import org.eclipse.lsp4j.TextDocumentSyncKind; | ||
import org.eclipse.lsp4j.jsonrpc.Launcher; | ||
import org.eclipse.lsp4j.launch.LSPLauncher; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.lsp4j.services.LanguageClientAware; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Main language server protocol implementation for NVList. | ||
*/ | ||
public final class NvlistLangServer implements LanguageServer, LanguageClientAware, Closeable { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(NvlistLangServer.class); | ||
|
||
private final NvlistTextDocumentService textDocumentService = new NvlistTextDocumentService(); | ||
private final NvlistWorkspaceService workspaceService = new NvlistWorkspaceService(); | ||
private Future<Void> messageHandler; | ||
|
||
public static void start(InputStream in, OutputStream out) throws IOException { | ||
LOG.info("Starting NVList language server..."); | ||
|
||
NvlistLangServer server = new NvlistLangServer(); | ||
Launcher<LanguageClient> launcher = new LSPLauncher.Builder<LanguageClient>() | ||
.setLocalService(server) | ||
.setRemoteInterface(LanguageClient.class) | ||
.setInput(in) | ||
.setOutput(out) | ||
.traceMessages(new PrintWriter(Files.newBufferedWriter(Paths.get("nvlist-langserver-trace.log")))) | ||
.create(); | ||
LanguageClient peer = launcher.getRemoteProxy(); | ||
server.connect(peer); | ||
server.messageHandler = launcher.startListening(); | ||
} | ||
|
||
@Override | ||
public void connect(LanguageClient client) { | ||
textDocumentService.connect(client); | ||
} | ||
|
||
|
||
@Override | ||
public void close() { | ||
LOG.info("Closing NVList language server..."); | ||
|
||
messageHandler.cancel(true); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<InitializeResult> initialize(InitializeParams params) { | ||
LOG.info("Received initialize request ({})", params); | ||
|
||
ServerCapabilities caps = new ServerCapabilities(); | ||
caps.setTextDocumentSync(TextDocumentSyncKind.Full); | ||
caps.setDefinitionProvider(true); | ||
|
||
InitializeResult result = new InitializeResult(); | ||
result.setCapabilities(caps); | ||
return CompletableFuture.completedFuture(result); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Object> shutdown() { | ||
LOG.info("Received shutdown request"); | ||
|
||
// TODO: Implement | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
@Override | ||
public void exit() { | ||
close(); | ||
} | ||
|
||
@Override | ||
public NvlistTextDocumentService getTextDocumentService() { | ||
return textDocumentService; | ||
} | ||
|
||
@Override | ||
public NvlistWorkspaceService getWorkspaceService() { | ||
return workspaceService; | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
langserver/src/main/java/nl/weeaboo/vn/langserver/NvlistTextDocumentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package nl.weeaboo.vn.langserver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.lsp4j.DefinitionParams; | ||
import org.eclipse.lsp4j.DidChangeTextDocumentParams; | ||
import org.eclipse.lsp4j.DidCloseTextDocumentParams; | ||
import org.eclipse.lsp4j.DidOpenTextDocumentParams; | ||
import org.eclipse.lsp4j.DidSaveTextDocumentParams; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.LocationLink; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.TextDocumentItem; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.lsp4j.services.LanguageClientAware; | ||
import org.eclipse.lsp4j.services.TextDocumentService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import nl.weeaboo.vn.core.NovelPrefs; | ||
import nl.weeaboo.vn.impl.script.lvn.ILvnParser; | ||
import nl.weeaboo.vn.impl.script.lvn.LvnParserFactory; | ||
|
||
final class NvlistTextDocumentService implements TextDocumentService, LanguageClientAware { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(NvlistTextDocumentService.class); | ||
|
||
@SuppressWarnings("unused") | ||
private LanguageClient peer; | ||
|
||
NvlistTextDocumentService() { | ||
} | ||
|
||
@Override | ||
public void connect(LanguageClient client) { | ||
this.peer = client; | ||
} | ||
|
||
private static ILvnParser getLvnParser() { | ||
// TODO: Use actual engine target version based on config | ||
return LvnParserFactory.getParser(NovelPrefs.ENGINE_TARGET_VERSION.getDefaultValue()); | ||
} | ||
|
||
@Override | ||
public void didOpen(DidOpenTextDocumentParams params) { | ||
LOG.debug("didOpen({})", params); | ||
|
||
TextDocumentItem doc = params.getTextDocument(); | ||
|
||
TODO: Modify LvnParser to return (optionally) a full AST instead of just a string | ||
getLvnParser().parseFile(filename, in) | ||
new LvnParserFactory().getParser(engineVersion).getText(); | ||
} | ||
|
||
@Override | ||
public void didChange(DidChangeTextDocumentParams params) { | ||
LOG.debug("didChange({})", params); | ||
} | ||
|
||
@Override | ||
public void didClose(DidCloseTextDocumentParams params) { | ||
LOG.debug("didClose({})", params); | ||
} | ||
|
||
@Override | ||
public void didSave(DidSaveTextDocumentParams params) { | ||
LOG.debug("didSave({})", params); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definition( | ||
DefinitionParams params) { | ||
|
||
List<Location> locations = new ArrayList<>(); | ||
|
||
Location loc = new Location(); | ||
// TODO: Implement properly | ||
loc.setUri(params.getTextDocument().getUri()); | ||
loc.setRange(new Range(new Position(0, 0), new Position(0, 10))); | ||
locations.add(loc); | ||
|
||
return CompletableFuture.completedFuture(Either.forLeft(locations)); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
langserver/src/main/java/nl/weeaboo/vn/langserver/NvlistWorkspaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package nl.weeaboo.vn.langserver; | ||
|
||
import org.eclipse.lsp4j.DidChangeConfigurationParams; | ||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams; | ||
import org.eclipse.lsp4j.services.WorkspaceService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
final class NvlistWorkspaceService implements WorkspaceService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(NvlistWorkspaceService.class); | ||
|
||
NvlistWorkspaceService() { | ||
} | ||
|
||
@Override | ||
public void didChangeConfiguration(DidChangeConfigurationParams params) { | ||
LOG.debug("disChangeConfiguration({})", params); | ||
} | ||
|
||
@Override | ||
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) { | ||
LOG.debug("didChangeWatchedFiles({})", params); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<configuration> | ||
<appender name="file" class="ch.qos.logback.core.FileAppender"> | ||
<file>nvlist-langserver.log</file> | ||
<append>false</append> | ||
<encoder> | ||
<pattern>| %-5level | %msg | %file:%line | %thread%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="debug"> | ||
<appender-ref ref="file" /> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters