From cc91e2eff6b0cac62f059cbeff8ddb4259c16315 Mon Sep 17 00:00:00 2001 From: Theodor Kvalsvik Lauritzen Date: Fri, 25 Oct 2024 15:06:32 +0200 Subject: [PATCH 1/5] feat: Add LSP4IJ --- .../clients/intellij/build.gradle.kts | 3 +- .../intellij/SchemaLanguageServer4IJ.java | 33 +++++++++++++++++++ .../intellij/SchemaLanguageServerFactory.java | 14 ++++++++ .../src/main/resources/META-INF/plugin.xml | 13 +++++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServer4IJ.java create mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServerFactory.java diff --git a/integration/schema-language-server/clients/intellij/build.gradle.kts b/integration/schema-language-server/clients/intellij/build.gradle.kts index 2bc087ab8c42..9e4032b7ee4f 100644 --- a/integration/schema-language-server/clients/intellij/build.gradle.kts +++ b/integration/schema-language-server/clients/intellij/build.gradle.kts @@ -38,6 +38,7 @@ dependencies { intellijPlatform { intellijIdeaUltimate("2024.2") instrumentationTools() + plugin("com.redhat.devtools.lsp4ij:0.7.0") } } @@ -94,4 +95,4 @@ tasks { publishPlugin { token.set(System.getenv("PUBLISH_TOKEN")) } -} +} \ No newline at end of file diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServer4IJ.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServer4IJ.java new file mode 100644 index 000000000000..34e72d2fe6c2 --- /dev/null +++ b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServer4IJ.java @@ -0,0 +1,33 @@ +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.util.Arrays; +import java.util.List; +import com.intellij.openapi.extensions.PluginId; +import com.intellij.ide.plugins.PluginManagerCore; + +public class SchemaLanguageServer4IJ extends ProcessStreamConnectionProvider { + + public SchemaLanguageServer4IJ(Project project) { + PluginId id = PluginId.getId("ai.vespa"); + var plugin = PluginManagerCore.getPlugin(id); + if (plugin == null) { + throw new IllegalStateException("Plugin " + id + " not found. Cannot start the Vespa Schema Language Support plugin."); + } + var pluginPath = plugin.getPluginPath(); + + var serverPath = pluginPath + .resolve("schema-language-server-jar-with-dependencies.jar") + .toAbsolutePath() + .toString(); + + List commands = new JavaProcessCommandBuilder(project, "vespaSchemaLanguageServer") + .setJar(serverPath) + .create(); + super.setCommands(commands); + } + +} diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServerFactory.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServerFactory.java new file mode 100644 index 000000000000..e5f85c8ff9a8 --- /dev/null +++ b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaLanguageServerFactory.java @@ -0,0 +1,14 @@ +package ai.vespa.schemals.intellij; + +import com.intellij.openapi.project.Project; +import com.redhat.devtools.lsp4ij.LanguageServerFactory; +import com.redhat.devtools.lsp4ij.client.LanguageClientImpl; +import com.redhat.devtools.lsp4ij.server.StreamConnectionProvider; +import org.jetbrains.annotations.NotNull; + +public class SchemaLanguageServerFactory implements LanguageServerFactory { + @Override + public @NotNull StreamConnectionProvider createConnectionProvider(@NotNull Project project) { + return new SchemaLanguageServer4IJ(project); + } +} diff --git a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml index 39f4a3e9148f..47a0115ebd50 100644 --- a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml +++ b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml @@ -35,11 +35,22 @@ ]]> com.intellij.modules.platform com.intellij.modules.ultimate - + com.redhat.devtools.lsp4ij + + + + + Date: Fri, 25 Oct 2024 15:23:31 +0200 Subject: [PATCH 2/5] refactor: Remove replaced code --- .../intellij/SchemaSyntaxHighlighter.java | 69 ------- .../intellij/settings/SchemaSettings.java | 41 ---- .../settings/SchemaSettingsComponent.java | 56 ------ .../settings/SchemaSettingsConfigurable.java | 61 ------ .../schemals/parser/SchemaIntellijLexer.java | 190 ------------------ .../ai/vespa/schemals/parser/SchemaTypes.java | 23 --- .../vespa/schemals/intellij/SchemaFileType.kt | 29 --- .../SchemaLspServerSupportProvider.kt | 58 ------ .../src/main/resources/META-INF/plugin.xml | 27 +-- 9 files changed, 3 insertions(+), 551 deletions(-) delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaSyntaxHighlighter.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettings.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsComponent.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsConfigurable.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaIntellijLexer.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaTypes.java delete mode 100644 integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaFileType.kt delete mode 100644 integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaLspServerSupportProvider.kt diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaSyntaxHighlighter.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaSyntaxHighlighter.java deleted file mode 100644 index e79c4ce0eca4..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/SchemaSyntaxHighlighter.java +++ /dev/null @@ -1,69 +0,0 @@ -package ai.vespa.schemals.intellij; - -import ai.vespa.schemals.parser.SchemaIntellijLexer; -import ai.vespa.schemals.parser.SchemaTypes; -import com.intellij.lexer.Lexer; -import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; -import com.intellij.openapi.editor.colors.TextAttributesKey; -import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; -import com.intellij.psi.tree.IElementType; -import org.jetbrains.annotations.NotNull; - -/** - * Entry point for providing syntax highlighting. - * Used in plugin.xml - */ -public class SchemaSyntaxHighlighter extends SyntaxHighlighterBase { - - private final TextAttributesKey[] KEYWORD = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD) - }; - private final TextAttributesKey[] TYPE = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_TYPE", DefaultLanguageHighlighterColors.CLASS_REFERENCE) - }; - private final TextAttributesKey[] NUMBER = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_NUMBER", DefaultLanguageHighlighterColors.NUMBER) - }; - - private final TextAttributesKey[] COMMENT = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT) - }; - - private final TextAttributesKey[] IDENTIFIER = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_IDENTIFIER", DefaultLanguageHighlighterColors.IDENTIFIER) - }; - - private final TextAttributesKey[] STRING = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_STRING", DefaultLanguageHighlighterColors.STRING) - }; - - private final TextAttributesKey[] BOOLEAN = new TextAttributesKey[] { - TextAttributesKey.createTextAttributesKey("SCHEMA_BOOLEAN", DefaultLanguageHighlighterColors.CONSTANT) - }; - - - @Override - public @NotNull Lexer getHighlightingLexer() { - return new SchemaIntellijLexer(); - } - - @Override - public TextAttributesKey @NotNull [] getTokenHighlights(IElementType iElementType) { - if (iElementType.equals(SchemaTypes.KEYWORD)) { - return KEYWORD; - } else if (iElementType.equals(SchemaTypes.TYPE)) { - return TYPE; - } else if (iElementType.equals(SchemaTypes.NUMBER)) { - return NUMBER; - } else if (iElementType.equals(SchemaTypes.COMMENT)) { - return COMMENT; - } else if (iElementType.equals(SchemaTypes.IDENTIFIER)) { - return IDENTIFIER; - } else if (iElementType.equals(SchemaTypes.STRING)) { - return STRING; - } else if (iElementType.equals(SchemaTypes.BOOLEAN)) { - return BOOLEAN; - } - return new TextAttributesKey[0]; - } -}; diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettings.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettings.java deleted file mode 100644 index 81619a2236a3..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettings.java +++ /dev/null @@ -1,41 +0,0 @@ -package ai.vespa.schemals.intellij.settings; - - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.PersistentStateComponent; -import com.intellij.openapi.components.State; -import com.intellij.openapi.components.Storage; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -/** - * This is the 'Model' part of the Settings interface per MVC. - * It simply contains the current settings state. - */ -@State( - name = "ai.vespa.schemals.intellij.settings.SchemaLspSettings", - storages = @Storage("VespaSchemaSettings.xml") -) -public final class SchemaSettings implements PersistentStateComponent { - public static class State { - @NonNls - public String javaPath = ""; - } - - private State state = new State(); - - public static SchemaSettings getInstance() { - return ApplicationManager.getApplication() - .getService(SchemaSettings.class); - } - - @Override - public State getState() { - return state; - } - - @Override - public void loadState(@NotNull State state) { - this.state = state; - } -} diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsComponent.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsComponent.java deleted file mode 100644 index d51851fdf5be..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsComponent.java +++ /dev/null @@ -1,56 +0,0 @@ -package ai.vespa.schemals.intellij.settings; - -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; -import com.intellij.openapi.fileChooser.FileChooserPanel; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.util.ThrowableComputable; -import com.intellij.ui.components.JBLabel; -import com.intellij.ui.components.JBTextField; -import com.intellij.util.ui.FormBuilder; -import com.jetbrains.JBRFileDialog; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; - -/** - * This is the 'View' part of the Settings interface per MVC - * It defines the settings ui for the plugin. - */ -public class SchemaSettingsComponent { - private final JPanel mainPanel; - private final TextFieldWithBrowseButton javaPathTextField = new TextFieldWithBrowseButton(); - - public SchemaSettingsComponent() { - FileChooserDescriptor fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); - fileChooserDescriptor.setTitle("Select Path to Java Home"); - javaPathTextField.addBrowseFolderListener("Java Path", "Select path to java home", null, fileChooserDescriptor); - javaPathTextField.setToolTipText("Path to Java Home or directory containing a java executable. Will use the system installed version of java if not set."); - - mainPanel = FormBuilder.createFormBuilder() - .addLabeledComponent(new JBLabel("Path to java home:"), javaPathTextField, 1, false) - .addComponentFillVertically(new JPanel(), 0) - .getPanel(); - } - - public JPanel getPanel() { - return mainPanel; - } - - public JComponent getPreferredFocusedComponent() { - return javaPathTextField; - } - - @NotNull - public String getJavaPathText() { - return javaPathTextField.getText(); - } - - public void setJavaPathText(@NotNull String javaPath) { - javaPathTextField.setText(javaPath); - } -} diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsConfigurable.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsConfigurable.java deleted file mode 100644 index e460d169ee29..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/intellij/settings/SchemaSettingsConfigurable.java +++ /dev/null @@ -1,61 +0,0 @@ -package ai.vespa.schemals.intellij.settings; - -import com.intellij.openapi.options.Configurable; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.util.Objects; - -/** - * This is the 'Controller' part of the Settings interface per MVC - * It glues the ui and the state together and interacts with the IntelliJ platform. - */ -public class SchemaSettingsConfigurable implements Configurable { - private SchemaSettingsComponent settingsComponent; - - @Nls(capitalization = Nls.Capitalization.Title) - @Override - public String getDisplayName() { - return "Vespa Schema Settings"; - } - - @Override - public JComponent getPreferredFocusedComponent() { - return settingsComponent.getPreferredFocusedComponent(); - } - - @Nullable - @Override - public JComponent createComponent() { - settingsComponent = new SchemaSettingsComponent(); - return settingsComponent.getPanel(); - } - - @Override - public boolean isModified() { - SchemaSettings.State state = - Objects.requireNonNull(SchemaSettings.getInstance().getState()); - return !settingsComponent.getJavaPathText().equals(state.javaPath); - } - - @Override - public void apply() { - SchemaSettings.State state = - Objects.requireNonNull(SchemaSettings.getInstance().getState()); - state.javaPath = settingsComponent.getJavaPathText(); - } - - @Override - public void reset() { - SchemaSettings.State state = - Objects.requireNonNull(SchemaSettings.getInstance().getState()); - settingsComponent.setJavaPathText(state.javaPath); - } - - @Override - public void disposeUIResources() { - settingsComponent = null; - } -} diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaIntellijLexer.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaIntellijLexer.java deleted file mode 100644 index bfd30abd225f..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaIntellijLexer.java +++ /dev/null @@ -1,190 +0,0 @@ -package ai.vespa.schemals.parser; - -import com.intellij.lexer.LexerBase; -import com.intellij.psi.tree.IElementType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * This class acts as a proxy for the generated {@link SchemaParserLexer} from CongoCC. - * IntelliJ syntax highlighting is lexer-based, requiring an incremental lexer extending {@link com.intellij.lexer.Lexer}. - * This class emulates the incremental behavior by constructing a fake starting token ending at the requested startOffset. - * I have not found a way around creating a new {@link SchemaParserLexer} object at each call to - * start, because the CongoCC lexer builds a cache and data structures based on the string content it first receives. - */ -public class SchemaIntellijLexer extends LexerBase { - int endOffset; - CharSequence buffer; - SchemaParserLexer schemaLexer; - Token currentToken; - boolean isInWhitespace = false; - int whitespacePointer = 0; - @Override - public void start(@NotNull CharSequence buffer, int startOffset, int endOffset, int initialState) { - this.endOffset = endOffset; - this.buffer = buffer; - - schemaLexer = new SchemaParserLexer(buffer); - currentToken = new Token(); - currentToken.setBeginOffset(startOffset); - currentToken.setEndOffset(startOffset); - isInWhitespace = false; - advance(); - } - - @Override - public int getState() { - return schemaLexer.lexicalState.ordinal(); - } - - @Override - public @Nullable IElementType getTokenType() { - if (getTokenStart() == endOffset) return null; - Token.TokenType type = currentToken.getType(); - - // some type keywords do not get recognized as a token type in lexer - if (currentToken.toString().equals("int") - || currentToken.toString().equals("bool") - || currentToken.toString().equals("byte") - || currentToken.toString().equals("position") - || currentToken.toString().equals("predicate")) { - type = Token.TokenType.LONG_KEYWORD; - } - switch (type) { - case ALIAS: - case ANNOTATION: - case APPROXIMATE_THRESHOLD: - case AS: - case ATTRIBUTE: - case BOLDING: - case CONSTANT: - case CONSTANTS: - case DIVERSITY: - case DOCUMENT: - case DOCUMENT_SUMMARY: - case EXPRESSION_ML: - case EXPRESSION_SL: - case FIELD: - case FIELDS: - case FIELDSET: - case FIRST_PHASE: - case FUNCTION: - case GLOBAL_PHASE: - case ID: - case IGNORE_DEFAULT_RANK_FEATURES: - case IMPORT: - case INDEX: - case INDEXING: - case INHERITS: - case INPUTS: - case MACRO: - case MATCH: - case MATCH_PHASE: - case MUTATE: - case NORMALIZING: - case NUM_SEARCH_PARTITIONS: - case NUM_THREADS_PER_SEARCH: - case ONNX_MODEL: - case POST_FILTER_THRESHOLD: - case QUERY_COMMAND: - case RANK: - case RANK_PROFILE: - case RANK_PROPERTIES: - case RANK_TYPE: - case RAW_AS_BASE64_IN_SUMMARY: - case SCHEMA: - case SEARCH: - case SECOND_PHASE: - case SORTING: - case STEMMING: - case STRICT: - case STRUCT: - case STRUCT_FIELD: - case SUMMARY: - case SUMMARY_TO: - case TARGET_HITS_MAX_ADJUSTMENT_FACTOR: - case TERMWISE_LIMIT: - case TYPE: - case WEIGHT: - case WEIGHTEDSET: - return SchemaTypes.KEYWORD; - case MAP: - case ARRAY: - case STRING_KEYWORD: - case ANNOTATIONREFERENCE: - case TENSOR_TYPE: - case REFERENCE: - case FLOAT_KEYWORD: - case LONG_KEYWORD: - case URI: - case RAW: - return SchemaTypes.TYPE; - case INTEGER: - case LONG: - case DOUBLE: - return SchemaTypes.NUMBER; - case DOUBLEQUOTEDSTRING: - case SINGLEQUOTEDSTRING: - case URI_PATH: - return SchemaTypes.STRING; - case SINGLE_LINE_COMMENT: - return SchemaTypes.COMMENT; - case IDENTIFIER: - case IDENTIFIER_WITH_DASH: - return SchemaTypes.IDENTIFIER; - case ON: - case OFF: - case TRUE: - case FALSE: - return SchemaTypes.BOOLEAN; - default: - return SchemaTypes.NONE; - } - } - - @Override - public int getTokenStart() { - if (isInWhitespace) { - return whitespacePointer; - } - return currentToken.getBeginOffset(); - } - - @Override - public int getTokenEnd() { - if (isInWhitespace) { - return whitespacePointer + 1; - } - return currentToken.getEndOffset(); - } - - @Override - public void advance() { - if (isInWhitespace) { - whitespacePointer++; - // when inside whitespace, currentToken holds next token that is not whitespace - if (whitespacePointer == currentToken.getBeginOffset()) { - isInWhitespace = false; - } - } else { - int saveEndOffset = currentToken.getEndOffset(); - currentToken = schemaLexer.getNextToken(currentToken); - - if (saveEndOffset < currentToken.getBeginOffset() || currentToken.getBeginOffset() == endOffset) { - isInWhitespace = true; - whitespacePointer = saveEndOffset; - } - } - } - - @Override - public @NotNull CharSequence getBufferSequence() { - return buffer; - } - - @Override - public int getBufferEnd() { - return endOffset; - } -} - diff --git a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaTypes.java b/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaTypes.java deleted file mode 100644 index 04d58ffd0269..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/java/ai/vespa/schemals/parser/SchemaTypes.java +++ /dev/null @@ -1,23 +0,0 @@ -package ai.vespa.schemals.parser; - -import ai.vespa.schemals.intellij.SchemaLanguage; -import com.intellij.psi.tree.IElementType; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; - -public class SchemaTypes { - private static class SchemaElementType extends IElementType { - public SchemaElementType(@NonNls @NotNull String debugName) { - super(debugName, SchemaLanguage.INSTANCE); - } - } - - public final static IElementType KEYWORD = new SchemaElementType("keyword"); - public final static IElementType NONE = new SchemaElementType("none"); - public final static IElementType TYPE = new SchemaElementType("type"); - public final static IElementType NUMBER = new SchemaElementType("number"); - public final static IElementType COMMENT = new SchemaElementType("comment"); - public final static IElementType IDENTIFIER = new SchemaElementType("identifier"); - public final static IElementType STRING = new SchemaElementType("string"); - public final static IElementType BOOLEAN = new SchemaElementType("boolean"); -} \ No newline at end of file diff --git a/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaFileType.kt b/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaFileType.kt deleted file mode 100644 index b48299a0d162..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaFileType.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ai.vespa.schemals.intellij - -import com.intellij.lang.Language -import com.intellij.openapi.fileTypes.LanguageFileType -import com.intellij.openapi.util.IconLoader -import javax.swing.Icon - -object SchemaFileType : LanguageFileType(SchemaLanguage) { - override fun getName(): String { - return "Schema" - } - - override fun getDescription(): String { - return "Schema file" - } - - override fun getDefaultExtension(): String { - return "sd" - } - - override fun getIcon(): Icon { - return IconLoader.getIcon("/icons/icon.svg", this.javaClass) - } -} - -object SchemaLanguage : Language("Schema") { - private fun readResolve(): Any = SchemaLanguage - override fun getDisplayName() = "Schema" -} diff --git a/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaLspServerSupportProvider.kt b/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaLspServerSupportProvider.kt deleted file mode 100644 index e1a2259cc932..000000000000 --- a/integration/schema-language-server/clients/intellij/src/main/kotlin/ai/vespa/schemals/intellij/SchemaLspServerSupportProvider.kt +++ /dev/null @@ -1,58 +0,0 @@ -package ai.vespa.schemals.intellij - -import com.intellij.execution.configurations.GeneralCommandLine -import com.intellij.ide.plugins.PluginManagerCore -import com.intellij.openapi.extensions.PluginId -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.platform.lsp.api.LspServerSupportProvider -import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor -import ai.vespa.schemals.intellij.settings.SchemaSettings -import java.nio.file.Paths -import kotlin.io.path.isExecutable - -/** - * Entry point for giving LSP support by starting the server. - * Used in plugin.xml - */ -internal class SchemaLspServerSupportProvider : LspServerSupportProvider { - override fun fileOpened( - project: Project, - file: VirtualFile, - serverStarter: LspServerSupportProvider.LspServerStarter - ) { - if (file.extension.equals("sd") || file.extension.equals("profile")) { - serverStarter.ensureServerStarted(SchemaLspServerDescriptor(project)); - } - } -} - -class SchemaLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Schema LSP Server") { - override fun isSupportedFile(file: VirtualFile) = file.extension.equals("sd") || file.extension.equals("profile") - - override fun createCommandLine(): GeneralCommandLine { - val id = PluginId.getId("ai.vespa") - val plugin = PluginManagerCore.getPlugin(id)!! - val pluginPath = plugin.getPluginPath() - - val serverPath = pluginPath - .resolve("schema-language-server-jar-with-dependencies.jar") - .toAbsolutePath() - .toString() - - // Check if user has supplied a custom path to java - val settingsState = SchemaSettings.getInstance().state - val javaPath = settingsState?.javaPath ?: "" - - val customJavaExecutable = listOf( - Paths.get(javaPath).resolve("java"), - Paths.get(javaPath).resolve("bin").resolve("java") - ).firstOrNull { it.isExecutable() } - - return if (customJavaExecutable != null) { - GeneralCommandLine(customJavaExecutable.toString(), "-jar", serverPath) - } else { - GeneralCommandLine("java", "-jar", serverPath) - } - } -} diff --git a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml index 47a0115ebd50..cd260acd413d 100644 --- a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml +++ b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml @@ -15,14 +15,12 @@
  • Code actions, including Quick fixes
  • Code completion
  • Go-to-definition
  • +
  • Go-to-references
  • Documentation on hover
  • Syntax highlighting
  • +
  • Renaming
  • -

    Settings:

    -

    If you encounter issues running the language server, you can supply a custom path to java by changing the setting under "Languages & Frameworks": "Vespa Schema Language Server"

    -

    The language server requires Java 17 or higher. The supplied path should contain a java binary or a subdirectory "bin" containing the java binary.

    - ]]> Rewritten from scratch to include LSP support @@ -34,34 +32,15 @@ ]]> com.intellij.modules.platform - com.intellij.modules.ultimate com.redhat.devtools.lsp4ij - - - - - - - - From 443cd560fb8f2cbcbcc7fe88345995f99f8cab3d Mon Sep 17 00:00:00 2001 From: Theodor Kvalsvik Lauritzen Date: Fri, 25 Oct 2024 15:28:01 +0200 Subject: [PATCH 3/5] chore: Update the IntelliJ plugin change notes --- .../intellij/src/main/resources/META-INF/plugin.xml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml index cd260acd413d..23719b0725d1 100644 --- a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml +++ b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml @@ -23,13 +23,8 @@ ]]> Rewritten from scratch to include LSP support -
      -
    • Error and warning highlighting
    • -
    • Code actions, including Quick fixes
    • -
    • Code completion
    • -
    • Documentation on hover
    • -
    +

    Refactored to use LSP4IJ

    +The plugin will now support better syntax highlighting with semantic tokens and renaming. ]]>
    com.intellij.modules.platform com.redhat.devtools.lsp4ij From e70237a8e47970bf7d61a82a757a20d557cef8f7 Mon Sep 17 00:00:00 2001 From: Theodor Kvalsvik Lauritzen Date: Fri, 25 Oct 2024 15:42:48 +0200 Subject: [PATCH 4/5] feat: Add support for Jetbrains Community editors --- .../schema-language-server/clients/intellij/build.gradle.kts | 2 +- .../clients/intellij/src/main/resources/META-INF/plugin.xml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/integration/schema-language-server/clients/intellij/build.gradle.kts b/integration/schema-language-server/clients/intellij/build.gradle.kts index 9e4032b7ee4f..c250f4b84a0b 100644 --- a/integration/schema-language-server/clients/intellij/build.gradle.kts +++ b/integration/schema-language-server/clients/intellij/build.gradle.kts @@ -36,7 +36,7 @@ dependencies { implementation("com.vladsch.flexmark:flexmark-html2md-converter:0.64.8") intellijPlatform { - intellijIdeaUltimate("2024.2") + intellijIdeaCommunity("2024.2") instrumentationTools() plugin("com.redhat.devtools.lsp4ij:0.7.0") } diff --git a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml index 23719b0725d1..ad6afd97ab14 100644 --- a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml +++ b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml @@ -25,6 +25,10 @@ Refactored to use LSP4IJ The plugin will now support better syntax highlighting with semantic tokens and renaming. +<<<<<<< HEAD +======= +In addition, the plugin will be available for community editions as well. +>>>>>>> 25ae8f2cc2f (chore: Update the IntelliJ plugin change notes) ]]> com.intellij.modules.platform com.redhat.devtools.lsp4ij From abf6e4ebe99b2d0a6d9df2db68b8a7c537488312 Mon Sep 17 00:00:00 2001 From: Theodor Kvalsvik Lauritzen Date: Fri, 25 Oct 2024 15:52:44 +0200 Subject: [PATCH 5/5] chore: Fix changes note for intelliJ plugin --- .../clients/intellij/src/main/resources/META-INF/plugin.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml index ad6afd97ab14..92b5b8c7d9dd 100644 --- a/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml +++ b/integration/schema-language-server/clients/intellij/src/main/resources/META-INF/plugin.xml @@ -25,10 +25,7 @@ Refactored to use LSP4IJ The plugin will now support better syntax highlighting with semantic tokens and renaming. -<<<<<<< HEAD -======= In addition, the plugin will be available for community editions as well. ->>>>>>> 25ae8f2cc2f (chore: Update the IntelliJ plugin change notes) ]]> com.intellij.modules.platform com.redhat.devtools.lsp4ij