-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32931 from vespa-engine/interns/magnus/xmlintellij
Interns/magnus/xmlintellij
- Loading branch information
Showing
9 changed files
with
177 additions
and
43 deletions.
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
49 changes: 49 additions & 0 deletions
49
...-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/LemminxVespaClient.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,49 @@ | ||
package ai.vespa.schemals.intellij; | ||
import com.intellij.openapi.project.Project; | ||
import com.redhat.devtools.lsp4ij.LanguageServerManager; | ||
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl; | ||
import com.redhat.devtools.lsp4ij.commands.CommandExecutor; | ||
import com.redhat.devtools.lsp4ij.commands.LSPCommandContext; | ||
import org.eclipse.lsp4j.*; | ||
import org.eclipse.lsp4j.jsonrpc.CompletableFutures; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; | ||
import org.eclipse.lemminx.customservice.XMLLanguageClientAPI; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/* | ||
The XMLLanguageClientAPI from LemMinX declares the custom LSP extensions they made. | ||
It is two things: | ||
- JSON Notification: "actionableNotification" (throws UnsupportedOperationException unless implemented here) | ||
- JSON Request: "executeClientCommand" (this is the reason we implement it). | ||
*/ | ||
public class LemminxVespaClient extends LanguageClientImpl implements XMLLanguageClientAPI { | ||
|
||
private static final Map<String, String> clientVespaCommands = Map.of( | ||
"vespaSchemaLS.commands.schema.findSchemaDefinition", "FIND_SCHEMA_DEFINITION", | ||
"vespaSchemaLS.commands.schema.setupWorkspace", "SETUP_WORKSPACE", | ||
"vespaSchemaLS.commands.schema.hasSetupWorkspace", "HAS_SETUP_WORKSPACE", | ||
"vespaSchemaLS.commands.schema.createSchemaFile", "CREATE_SCHEMA_FILE", | ||
"vespaSchemaLS.commands.schema.getDefinedSchemas", "GET_DEFINED_SCHEMAS" | ||
); | ||
|
||
public LemminxVespaClient(Project project) { super(project); } | ||
|
||
@Override | ||
public CompletableFuture<Object> executeClientCommand(ExecuteCommandParams params) { | ||
super.logMessage(new MessageParams(MessageType.Info, "Execute: " + params.toString())); | ||
String commandKey = params.getCommand(); | ||
|
||
if (!clientVespaCommands.containsKey(commandKey)) { | ||
return null; | ||
} | ||
|
||
// Forward command to vespa schema LS | ||
Command command = new Command("SchemaCommand", clientVespaCommands.get(commandKey)); | ||
command.setArguments(params.getArguments()); | ||
LSPCommandContext context = new LSPCommandContext(command, getProject()); | ||
context.setPreferredLanguageServerId("vespaSchemaLanguageServer"); | ||
return CommandExecutor.executeCommand(context).response(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/LemminxVespaServer.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,51 @@ | ||
package ai.vespa.schemals.intellij; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.redhat.devtools.lsp4ij.server.JavaProcessCommandBuilder; | ||
import com.redhat.devtools.lsp4ij.server.ProcessStreamConnectionProvider; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import com.intellij.openapi.extensions.PluginId; | ||
import com.intellij.ide.plugins.PluginManagerCore; | ||
|
||
public class LemminxVespaServer extends ProcessStreamConnectionProvider { | ||
public LemminxVespaServer(Project project) { | ||
PluginId id = PluginId.getId("ai.vespa"); | ||
var vespaPlugin = PluginManagerCore.getPlugin(id); | ||
if (vespaPlugin == null) { | ||
throw new IllegalStateException("Plugin " + id + " not found. Cannot start the Vespa Schema Language Support plugin."); | ||
} | ||
var vespaPluginPath = vespaPlugin.getPluginPath(); | ||
|
||
var lsp4ijPlugin = PluginManagerCore.getPlugin(PluginId.getId("com.redhat.devtools.lsp4ij")); | ||
if (lsp4ijPlugin == null) { | ||
throw new IllegalStateException("LSP4IJ could not be found. Cannot start the Vespa Schema Language Support plugin."); | ||
} | ||
|
||
var vespaServerPath = vespaPluginPath | ||
.resolve("lemminx-vespa-jar-with-dependencies.jar") | ||
.toAbsolutePath() | ||
.toString(); | ||
|
||
var lemminxPath = vespaPluginPath | ||
.resolve("lib") | ||
.resolve("*") | ||
.toAbsolutePath() | ||
.toString(); | ||
|
||
var lsp4ijPath = lsp4ijPlugin.getPluginPath() | ||
.resolve("lib") | ||
.resolve("*") | ||
.toAbsolutePath() | ||
.toString(); | ||
|
||
List<String> commands = new JavaProcessCommandBuilder(project, "vespaLemminxLanguageServer") | ||
.setCp(lemminxPath + File.pathSeparator + vespaServerPath + File.pathSeparator + lsp4ijPath) | ||
.create(); | ||
commands.add("org.eclipse.lemminx.XMLServerLauncher"); | ||
|
||
super.setCommands(commands); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../clients/intellij/src/main/java/ai/vespa/schemals/intellij/LemminxVespaServerFactory.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,18 @@ | ||
package ai.vespa.schemals.intellij; | ||
import com.redhat.devtools.lsp4ij.LanguageServerFactory; | ||
import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider; | ||
import com.intellij.openapi.project.Project; | ||
import com.redhat.devtools.lsp4ij.client.LanguageClientImpl; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
|
||
public class LemminxVespaServerFactory implements LanguageServerFactory { | ||
@Override | ||
public StreamConnectionProvider createConnectionProvider(Project project) { | ||
return new LemminxVespaServer(project); | ||
} | ||
|
||
@Override | ||
public LanguageClientImpl createLanguageClient(Project project) { | ||
return new LemminxVespaClient(project); | ||
} | ||
} |
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
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