diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKGroovyDSLParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKGroovyDSLParser.java deleted file mode 100644 index d970106a..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKGroovyDSLParser.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser; - -public class CamelKGroovyDSLParser extends ParserJavaFileHelper { - - @Override - protected char getEnclosingStringCharacter() { - return '\''; - } - -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKJSDSLParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKJSDSLParser.java deleted file mode 100644 index 07528387..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKJSDSLParser.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser; - -public class CamelKJSDSLParser extends ParserJavaFileHelper { - - @Override - protected char getEnclosingStringCharacter() { - return '\''; - } - -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKKotlinDSLParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKKotlinDSLParser.java deleted file mode 100644 index 0faf8e65..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/CamelKKotlinDSLParser.java +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser; - -public class CamelKKotlinDSLParser extends ParserJavaFileHelper { - - //Same from/to detection than for Java, so nothing to extend -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelperFactory.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelperFactory.java index 069e7585..4af06d5c 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelperFactory.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/parser/ParserFileHelperFactory.java @@ -27,13 +27,10 @@ public class ParserFileHelperFactory { private static final String KUBERNETES_CRD_API_VERSION_CAMEL = "apiVersion: camel.apache.org/"; private static final String CAMELK_XML_FILENAME_SUFFIX = "camelk.xml"; - private static final String CAMELK_GROOVY_FILENAME_SUFFIX = ".camelk.groovy"; - private static final String CAMELK_KOTLIN_FILENAME_SUFFIX = ".camelk.kts"; private static final String CAMELK_YAML_FILENAME_SUFFIX = ".camelk.yaml"; private static final String PLAIN_CAMEL_YAML_FILENAME_SUFFIX = ".camel.yaml"; private static final String CAMELK_YML_FILENAME_SUFFIX = ".camelk.yml"; private static final String PLAIN_CAMEL_YML_FILENAME_SUFFIX = ".camel.yml"; - private static final String CAMELK_JS_FILENAME_SUFFIX = ".camelk.js"; private static final String SHEBANG_CAMEL_K = "#!/usr/bin/env camel-k"; public ParserFileHelper getCorrespondingParserFileHelper(TextDocumentItem textDocumentItem, int line) { @@ -48,10 +45,7 @@ public boolean isProbablyCamelFile(TextDocumentItem textDocumentItem) { String uri = textDocumentItem.getUri(); return isHighProbabilityCamelJavaDSL(textDocumentItem, uri) || isCamelXMLDSL(textDocumentItem, uri) - || isCamelKJSDSL(textDocumentItem, uri) - || isCamelYamlDSL(textDocumentItem, uri) - || isCamelKKotlinDSL(textDocumentItem, uri) - || isCamelKGroovyDSL(textDocumentItem, uri); + || isCamelYamlDSL(textDocumentItem, uri); } private boolean isCamelXMLDSL(TextDocumentItem textDocumentItem, String uri) { @@ -63,41 +57,6 @@ private boolean isCamelXMLDSL(TextDocumentItem textDocumentItem, String uri) { } } - public boolean isCamelKJSDSL(TextDocumentItem textDocumentItem, String uri) { - //improve this method to provide better heuristic to detect if it is a Camel file or not - return uri.endsWith(CAMELK_JS_FILENAME_SUFFIX) - || isJSFileWithCamelKModelineLike(textDocumentItem, uri); - } - - private boolean isJSFileWithCamelKModelineLike(TextDocumentItem textDocumentItem, String uri) { - return uri.endsWith(".js") && textDocumentItem.getText().startsWith(CamelKModelineParser.MODELINE_LIKE_CAMEL_K); - } - - public boolean isCamelKKotlinDSL(TextDocumentItem textDocumentItem, String uri) { - //improve this method to provide better heuristic to detect if it is a Camel file or not - return uri.endsWith(CAMELK_KOTLIN_FILENAME_SUFFIX) - || isKotlinFileWithCamelKModelineLike(textDocumentItem, uri); - } - - private boolean isKotlinFileWithCamelKModelineLike(TextDocumentItem textDocumentItem, String uri) { - return uri.endsWith(".kts") && textDocumentItem.getText().startsWith(CamelKModelineParser.MODELINE_LIKE_CAMEL_K); - } - - public boolean isCamelKGroovyDSL(TextDocumentItem textDocumentItem, String uri) { - //improve this method to provide better heuristic to detect if it is a Camel file or not - return uri.endsWith(CAMELK_GROOVY_FILENAME_SUFFIX) - || isGroovyFileWithCamelKShebang(textDocumentItem, uri) - || isGroovyFileWithCamelKModelineLike(textDocumentItem, uri); - } - - private boolean isGroovyFileWithCamelKModelineLike(TextDocumentItem textDocumentItem, String uri) { - return uri.endsWith(".groovy") && textDocumentItem.getText().startsWith(CamelKModelineParser.MODELINE_LIKE_CAMEL_K); - } - - protected boolean isGroovyFileWithCamelKShebang(TextDocumentItem textDocumentItem, String uri) { - return uri.endsWith(".groovy") && textDocumentItem.getText().startsWith(SHEBANG_CAMEL_K); - } - public boolean isCamelYamlDSL(TextDocumentItem textDocumentItem, String uri) { //improve this method to provide better heuristic to detect if it is a Camel file or not return uri.endsWith(CAMELK_YAML_FILENAME_SUFFIX) diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKGroovyDSLFileParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKGroovyDSLFileParser.java deleted file mode 100644 index de556d3a..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKGroovyDSLFileParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser.fileparserhelper; - -import com.github.cameltooling.lsp.internal.parser.CamelKGroovyDSLParser; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelper; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelperFactory; -import org.eclipse.lsp4j.TextDocumentItem; - -public class CamelKGroovyDSLFileParser extends Parser { - - private final Parser nextFileParser; - - CamelKGroovyDSLFileParser(Parser parser) { - this.nextFileParser = parser; - } - - @Override - public ParserFileHelper getMatchedFileParser(TextDocumentItem textDocumentItem, int line, ParserFileHelperFactory parserFileHelperFactory) { - String uri = textDocumentItem.getUri(); - if (parserFileHelperFactory.isCamelKGroovyDSL(textDocumentItem, uri)) { - CamelKGroovyDSLParser camelKGroovyDSLParser = new CamelKGroovyDSLParser(); - if (camelKGroovyDSLParser.getCorrespondingMethodName(textDocumentItem, line) != null) { - return camelKGroovyDSLParser; - } - } else if (nextFileParser != null) { - return nextFileParser.getMatchedFileParser(textDocumentItem, line, parserFileHelperFactory); - } - - return null; - } -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKJSDSLFileParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKJSDSLFileParser.java deleted file mode 100644 index d0554ac0..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKJSDSLFileParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser.fileparserhelper; - -import com.github.cameltooling.lsp.internal.parser.CamelKJSDSLParser; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelper; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelperFactory; -import org.eclipse.lsp4j.TextDocumentItem; - -public class CamelKJSDSLFileParser extends Parser { - - private final Parser nextFileParser; - - CamelKJSDSLFileParser(Parser parser) { - this.nextFileParser = parser; - } - - @Override - public ParserFileHelper getMatchedFileParser(TextDocumentItem textDocumentItem, int line, ParserFileHelperFactory parserFileHelperFactory) { - String uri = textDocumentItem.getUri(); - if (parserFileHelperFactory.isCamelKJSDSL(textDocumentItem, uri)) { - CamelKJSDSLParser camelKJSDSLParser = new CamelKJSDSLParser(); - if (camelKJSDSLParser.getCorrespondingMethodName(textDocumentItem, line) != null) { - return camelKJSDSLParser; - } - } else if (nextFileParser != null) { - return nextFileParser.getMatchedFileParser(textDocumentItem, line, parserFileHelperFactory); - } - - return null; - } -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKKotlinDSLFileParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKKotlinDSLFileParser.java deleted file mode 100644 index 2141f511..00000000 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelKKotlinDSLFileParser.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.cameltooling.lsp.internal.parser.fileparserhelper; - -import com.github.cameltooling.lsp.internal.parser.CamelKKotlinDSLParser; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelper; -import com.github.cameltooling.lsp.internal.parser.ParserFileHelperFactory; -import org.eclipse.lsp4j.TextDocumentItem; - -public class CamelKKotlinDSLFileParser extends Parser { - - private final Parser nextFileParser; - - CamelKKotlinDSLFileParser(Parser parser) { - this.nextFileParser = parser; - } - - @Override - public ParserFileHelper getMatchedFileParser(TextDocumentItem textDocumentItem, int line, ParserFileHelperFactory parserFileHelperFactory) { - String uri = textDocumentItem.getUri(); - if (parserFileHelperFactory.isCamelKKotlinDSL(textDocumentItem, uri)) { - CamelKKotlinDSLParser camelKKotlinDSLParser = new CamelKKotlinDSLParser(); - if (camelKKotlinDSLParser.getCorrespondingMethodName(textDocumentItem, line) != null) { - return camelKKotlinDSLParser; - } - } else if (nextFileParser != null) { - return nextFileParser.getMatchedFileParser(textDocumentItem, line, parserFileHelperFactory); - } - - return null; - } - -} diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelYamlDSLFileParser.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelYamlDSLFileParser.java index 1e6c508b..ad726889 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelYamlDSLFileParser.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/CamelYamlDSLFileParser.java @@ -23,10 +23,7 @@ public class CamelYamlDSLFileParser extends Parser { - private final Parser nextFileParser; - - CamelYamlDSLFileParser(Parser parser) { - this.nextFileParser = parser; + CamelYamlDSLFileParser() { } @Override @@ -37,8 +34,6 @@ public ParserFileHelper getMatchedFileParser(TextDocumentItem textDocumentItem, if (camelKYamlDSLParser.getCorrespondingType(textDocumentItem, line) != null) { return camelKYamlDSLParser; } - } else if (nextFileParser != null) { - return nextFileParser.getMatchedFileParser(textDocumentItem, line, parserFileHelperFactory); } return null; diff --git a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/ParserChainOfResponsibility.java b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/ParserChainOfResponsibility.java index 327427bf..92d4ace6 100644 --- a/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/ParserChainOfResponsibility.java +++ b/src/main/java/com/github/cameltooling/lsp/internal/parser/fileparserhelper/ParserChainOfResponsibility.java @@ -23,12 +23,7 @@ public class ParserChainOfResponsibility { public static ParserFileHelper getMatchedParserFileHelper(TextDocumentItem textDocumentItem, int line, ParserFileHelperFactory parserFileHelperFactory) { - Parser fileParser = new XMLFileParser( - new JavaFileParser( - new CamelKGroovyDSLFileParser( - new CamelYamlDSLFileParser( - new CamelKKotlinDSLFileParser( - new CamelKJSDSLFileParser(null)))))); + Parser fileParser = new XMLFileParser(new JavaFileParser(new CamelYamlDSLFileParser())); return fileParser.getMatchedFileParser(textDocumentItem, line, parserFileHelperFactory); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/CamelCatalogRuntimeProviderTest.java b/src/test/java/com/github/cameltooling/lsp/internal/CamelCatalogRuntimeProviderTest.java index 57c092c3..b7ab84fe 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/CamelCatalogRuntimeProviderTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/CamelCatalogRuntimeProviderTest.java @@ -76,12 +76,13 @@ void testQuarkusValueSpecifiedReturnsQuarkusRuntimeProvider() throws Exception { private void testRuntimeProviderWithProvidedValue(String settingValue, Class expectedRuntimeProviderType) throws URISyntaxException, InterruptedException, ExecutionException { runtimeProvider = settingValue; - CamelLanguageServer camelLanguageServer = initializeLanguageServer("// camel-k: dependency=\nfrom('');", ".groovy"); + CamelLanguageServer camelLanguageServer = initializeLanguageServer( + "# camel-k: dependency=\n- from:\n uri: \"\"", ".yaml"); RuntimeProvider usedRuntimeProvider = camelLanguageServer.getTextDocumentService().getCamelCatalog().get().getRuntimeProvider(); assertThat(usedRuntimeProvider).isExactlyInstanceOf(expectedRuntimeProviderType); - CompletableFuture, CompletionList>> camelUriCompletion = getCompletionFor(camelLanguageServer, new Position(1, "from('".length())); + CompletableFuture, CompletionList>> camelUriCompletion = getCompletionFor(camelLanguageServer, new Position(2," uri: \"".length())); assertThat(camelUriCompletion.get().getLeft()).isNotEmpty(); - CompletableFuture, CompletionList>> dependencyCompletion = getCompletionFor(camelLanguageServer, new Position(0, "// camel-k: dependency=".length())); + CompletableFuture, CompletionList>> dependencyCompletion = getCompletionFor(camelLanguageServer, new Position(0, "# camel-k: dependency=".length())); assertThat(dependencyCompletion.get().getLeft()).isNotEmpty(); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/CamelLanguageServerTest.java b/src/test/java/com/github/cameltooling/lsp/internal/CamelLanguageServerTest.java index 9ee28800..e9858a89 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/CamelLanguageServerTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/CamelLanguageServerTest.java @@ -95,61 +95,6 @@ void testProvideCompletionForJavaOnRealFile() throws Exception { } } - @Test - void testProvideCompletionForGroovyOnRealFileWithCamelKExtension() throws Exception { - File f = new File("src/test/resources/workspace/sample.camelk.groovy"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".camelk.groovy"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(0, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(0, 6, 0, 25)); - } - } - - @Test - void testProvideCompletionForGroovyOnRealFileWithCamelKShebang() throws Exception { - File f = new File("src/test/resources/workspace/samplewithshebang.groovy"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".groovy"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(2, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(2, 6, 2, 25)); - } - } - - @Test - void testProvideCompletionForKotlinOnRealFileWithCamelKExtension() throws Exception { - File f = new File("src/test/resources/workspace/sample.camelk.kts"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".camelk.kts"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(0, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(0, 6, 0, 18)); - } - } - - @Test - void testProvideCompletionForJSOnRealFileWithCamelKExtension() throws Exception { - File f = new File("src/test/resources/workspace/sample.camelk.js"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".camelk.js"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(0, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(0, 6, 0, 14)); - } - } - - @Test - void testProvideCompletionForGroovyOnRealFileWithCamelKCloseToModeline() throws Exception { - File f = new File("src/test/resources/workspace/samplewithModelineLike.groovy"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".groovy"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(2, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(2, 6, 2, 25)); - } - } - @Nested class Yaml { @Test @@ -396,17 +341,6 @@ void testProvideCompletionForPlainYml() throws Exception { } } - @Test - void testProvideCompletionForkotlinOnRealFileWithCamelKCloseToModeline() throws Exception { - File f = new File("src/test/resources/workspace/sampleWithModelineLike.kts"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".kts"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(2, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(2, 6, 2, 18)); - } - } - @Test void testProvideCompletionForApplicationProperties() throws Exception { File f = new File("src/test/resources/workspace/application.properties"); @@ -419,18 +353,7 @@ void testProvideCompletionForApplicationProperties() throws Exception { assertThat(completions.get().getLeft()).hasSize(mainModel.getGroups().size() + 1); } } - - @Test - void testProvideCompletionForJSOnRealFileWithCamelKCloseToModeline() throws Exception { - File f = new File("src/test/resources/workspace/sampleWithModelineLike.js"); - assertThat(f).exists(); - try (FileInputStream fis = new FileInputStream(f)) { - CamelLanguageServer cls = initializeLanguageServer(fis, ".js"); - CompletableFuture, CompletionList>> completions = getCompletionFor(cls, new Position(2, 6)); - assertThat(completions.get().getLeft()).contains(createExpectedTimerCompletionItem(2, 6, 2, 14)); - } - } - + @Test void testProvideCompletionforMultilineXmlFile() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer( diff --git a/src/test/java/com/github/cameltooling/lsp/internal/codeactions/CamelKPropertyFileModelineDeprecatedRefactorTest.java b/src/test/java/com/github/cameltooling/lsp/internal/codeactions/CamelKPropertyFileModelineDeprecatedRefactorTest.java index 4cb6e89b..1358cddf 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/codeactions/CamelKPropertyFileModelineDeprecatedRefactorTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/codeactions/CamelKPropertyFileModelineDeprecatedRefactorTest.java @@ -43,17 +43,17 @@ class CamelKPropertyFileModelineDeprecatedRefactorTest extends AbstractCamelLang @Test void testRefactor() throws Exception { - testBasicRefactor("// camel-k: property-file=aFile.properties", "property=file:aFile.properties"); + testBasicRefactor("# camel-k: property-file=aFile.properties", "property=file:aFile.properties"); } @Test void testRefactorWithEmptyValue() throws Exception { - testBasicRefactor("// camel-k: property-file=", "property=file:"); + testBasicRefactor("# camel-k: property-file=", "property=file:"); } @Test void testRefactorWithNoEqual() throws Exception { - testBasicRefactor("// camel-k: property-file", "property=file:"); + testBasicRefactor("# camel-k: property-file", "property=file:"); } private void testBasicRefactor(String text, String expectedNewText) throws URISyntaxException, InterruptedException, ExecutionException { @@ -64,16 +64,16 @@ private void testBasicRefactor(String text, String expectedNewText) throws URISy assertThat(codeAction.getTitle()).isEqualTo(ConvertCamelKPropertyFileModelineRefactorAction.CODE_ACTION_TITLE_CONVERT_PROPERTY_FILE); Map> changes = codeAction.getEdit().getChanges(); assertThat(changes).hasSize(1); - List textEdits = changes.get(DUMMY_URI+".groovy"); + List textEdits = changes.get(DUMMY_URI+".yaml"); assertThat(textEdits).hasSize(1); TextEdit textEdit = textEdits.get(0); - assertThat(textEdit.getRange()).isEqualTo(new Range(new Position(0,12), new Position(0, text.length()))); + assertThat(textEdit.getRange()).isEqualTo(new Range(new Position(0,11), new Position(0, text.length()))); assertThat(textEdit.getNewText()).isEqualTo(expectedNewText); } @Test void testRefactorWithSeveralPropertyFileOptions() throws Exception { - String text = "// camel-k: property-file=aFile1.properties property-file=aFile2.properties"; + String text = "# camel-k: property-file=aFile1.properties property-file=aFile2.properties"; List> codeActions = retrieveCodeActions(text); assertThat(codeActions).hasSize(1); CodeAction codeAction = codeActions.get(0).getRight(); @@ -81,23 +81,23 @@ void testRefactorWithSeveralPropertyFileOptions() throws Exception { assertThat(codeAction.getTitle()).isEqualTo(ConvertCamelKPropertyFileModelineRefactorAction.CODE_ACTION_TITLE_CONVERT_PROPERTY_FILE); Map> changes = codeAction.getEdit().getChanges(); assertThat(changes).hasSize(1); - List textEdits = changes.get(DUMMY_URI+".groovy"); + List textEdits = changes.get(DUMMY_URI+".yaml"); assertThat(textEdits).hasSize(2); TextEdit textEdit1 = textEdits.get(0); - assertThat(textEdit1.getRange()).isEqualTo(new Range(new Position(0,12), new Position(0, 43))); + assertThat(textEdit1.getRange()).isEqualTo(new Range(new Position(0,11), new Position(0, 42))); assertThat(textEdit1.getNewText()).isEqualTo("property=file:aFile1.properties"); TextEdit textEdit2 = textEdits.get(1); - assertThat(textEdit2.getRange()).isEqualTo(new Range(new Position(0,44), new Position(0, text.length()))); + assertThat(textEdit2.getRange()).isEqualTo(new Range(new Position(0,43), new Position(0, text.length()))); assertThat(textEdit2.getNewText()).isEqualTo("property=file:aFile2.properties"); } private List> retrieveCodeActions(String text) throws URISyntaxException, InterruptedException, ExecutionException { - CamelLanguageServer languageServer = initializeLanguageServer(text, ".groovy"); + CamelLanguageServer languageServer = initializeLanguageServer(text, ".yaml"); CodeActionContext context = new CodeActionContext(Collections.emptyList(), Collections.singletonList(CodeActionKind.Refactor)); - Range range = new Range(new Position(0,14), new Position(0, 14)); - CodeActionParams params = new CodeActionParams(new TextDocumentIdentifier(DUMMY_URI+".groovy"), range, context); + Range range = new Range(new Position(0,13), new Position(0, 13)); + CodeActionParams params = new CodeActionParams(new TextDocumentIdentifier(DUMMY_URI+".yaml"), range, context); return languageServer.getTextDocumentService().codeAction(params).get(); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/completion/modeline/CamelKModelineCompletionTest.java b/src/test/java/com/github/cameltooling/lsp/internal/completion/modeline/CamelKModelineCompletionTest.java index 97dded46..3771b459 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/completion/modeline/CamelKModelineCompletionTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/completion/modeline/CamelKModelineCompletionTest.java @@ -74,9 +74,9 @@ private void checkTraitCompletionAvailable(List completionItems) @Test void testProvideCompletionAtTheEndOfLine() throws Exception { - CamelLanguageServer camelLanguageServer = initializeLanguageServer("// camel-k: language=groovy trait=service.enabled=false "); + CamelLanguageServer camelLanguageServer = initializeLanguageServer("# camel-k: language=yaml trait=service.enabled=false "); - CompletableFuture, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 56)); + CompletableFuture, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 53)); List completionItems = completions.get().getLeft(); assertThat(completionItems).hasSize(12); diff --git a/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineOptionTest.java b/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineOptionTest.java index 19d36aa2..8ee1f64b 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineOptionTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineOptionTest.java @@ -24,7 +24,7 @@ class CamelKModelineOptionTest { - String modelineString = "// camel-k: language=groovy"; + String modelineString = "# camel-k: language=yaml"; CamelKModeline basicModeline = new CamelKModeline(modelineString, null, 0); @Test @@ -33,45 +33,45 @@ void testOptionParsingBasic() throws Exception { assertThat(options).hasSize(1); CamelKModelineOption languageOption = options.get(0); assertThat(languageOption.getOptionName()).isEqualTo("language"); - assertThat(languageOption.getOptionValue().getValueAsString()).isEqualTo("groovy"); + assertThat(languageOption.getOptionValue().getValueAsString()).isEqualTo("yaml"); } @Test void testOptionTraitWithIncompleteTraitContent() throws Exception { - String modelineWithMixedSeparator = "// camel-k: language=groovy trait=quarkus"; + String modelineWithMixedSeparator = "# camel-k: language=yaml trait=quarkus"; List options = new CamelKModeline(modelineWithMixedSeparator, null, 0).getOptions(); assertThat(options).hasSize(2); } @Test void test2Options() throws Exception { - String modelineWith2Options = "// camel-k: language=groovy trait=quarkus.enabled=true"; + String modelineWith2Options = "# camel-k: language=yaml trait=quarkus.enabled=true"; checkFor2Options(modelineWith2Options); } @Test void test2OptionsWithTabSeparator() throws Exception { - String modelineWith2Options = "// camel-k:\tlanguage=groovy\ttrait=quarkus.enabled=true"; + String modelineWith2Options = "# camel-k:\tlanguage=yaml\ttrait=quarkus.enabled=true"; checkFor2Options(modelineWith2Options); } @Test void testOptionsWithMixedSeparator() throws Exception { - String modelineWithMixedSeparator = "// camel-k:\tlanguage=groovy trait=quarkus.enabled=true\tdependency=mvn:org.my/application:1.0"; + String modelineWithMixedSeparator = "# camel-k:\tlanguage=yaml trait=quarkus.enabled=true\tdependency=mvn:org.my/application:1.0"; List options = new CamelKModeline(modelineWithMixedSeparator, null, 0).getOptions(); assertThat(options).hasSize(3); } @Test void testOptionsWithIncompleteOptions() throws Exception { - String modelineWithMixedSeparator = "// camel-k: language=groovy trait"; + String modelineWithMixedSeparator = "# camel-k: language=yaml trait"; List options = new CamelKModeline(modelineWithMixedSeparator, null, 0).getOptions(); assertThat(options).hasSize(2); CamelKModelineOption incompleteOption = options.get(1); assertThat(incompleteOption.getOptionName()).isEqualTo("trait"); assertThat(incompleteOption.getOptionValue()).isNull(); - assertThat(incompleteOption.getStartPositionInLine()).isEqualTo(28); - assertThat(incompleteOption.getEndPositionInLine()).isEqualTo(33); + assertThat(incompleteOption.getStartPositionInLine()).isEqualTo(25); + assertThat(incompleteOption.getEndPositionInLine()).isEqualTo(30); } private void checkFor2Options(String modelineWith2Options) { @@ -79,13 +79,13 @@ private void checkFor2Options(String modelineWith2Options) { assertThat(options).hasSize(2); CamelKModelineOption languageGroovyOption = options.get(0); assertThat(languageGroovyOption.getOptionName()).isEqualTo("language"); - assertThat(languageGroovyOption.getOptionValue().getValueAsString()).isEqualTo("groovy"); - assertThat(languageGroovyOption.getStartPositionInLine()).isEqualTo(12); - assertThat(languageGroovyOption.getEndPositionInLine()).isEqualTo(27); + assertThat(languageGroovyOption.getOptionValue().getValueAsString()).isEqualTo("yaml"); + assertThat(languageGroovyOption.getStartPositionInLine()).isEqualTo(11); + assertThat(languageGroovyOption.getEndPositionInLine()).isEqualTo(24); CamelKModelineOption traitOption = options.get(1); assertThat(traitOption.getOptionName()).isEqualTo("trait"); assertThat(traitOption.getOptionValue().getValueAsString()).isEqualTo("quarkus.enabled=true"); - assertThat(traitOption.getStartPositionInLine()).isEqualTo(28); + assertThat(traitOption.getStartPositionInLine()).isEqualTo(25); assertThat(traitOption.getEndPositionInLine()).isEqualTo(modelineWith2Options.length()); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineTest.java b/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineTest.java index a97a9d2e..34b76690 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/modelinemodel/CamelKModelineTest.java @@ -30,12 +30,11 @@ class CamelKModelineTest { - String modelineString = "// camel-k: language=groovy"; + String modelineString = "# camel-k: language=yaml"; CamelKModeline basicModeline = new CamelKModeline(modelineString, null, 0); public static Stream data() { return Stream.of( - Arguments.of("// camel-k: language=groovy"), Arguments.of("# camel-k: language=yaml"), Arguments.of("")); } diff --git a/src/test/java/com/github/cameltooling/lsp/internal/telemetry/TelemetryTest.java b/src/test/java/com/github/cameltooling/lsp/internal/telemetry/TelemetryTest.java index a04c79a7..8d41247a 100644 --- a/src/test/java/com/github/cameltooling/lsp/internal/telemetry/TelemetryTest.java +++ b/src/test/java/com/github/cameltooling/lsp/internal/telemetry/TelemetryTest.java @@ -72,9 +72,7 @@ private static Stream testOpenedDocumentMetric() { return Stream.of( Arguments.of(RouteTextBuilder.createXMLSpringRoute(""), "xml"), Arguments.of(javaContent, "java"), - Arguments.of("# camel-k:", "yaml"), - Arguments.of("// camel-k:", "kts"), - Arguments.of("// camel-k:", "js") + Arguments.of("# camel-k:", "yaml") ); } diff --git a/src/test/resources/workspace/sample.camelk.groovy b/src/test/resources/workspace/sample.camelk.groovy deleted file mode 100644 index 25416e59..00000000 --- a/src/test/resources/workspace/sample.camelk.groovy +++ /dev/null @@ -1,4 +0,0 @@ -from('direct:greeting-api') - .to('log:api?showAll=true&multiline=true') - .setBody() - .simple('Hello from ${headers.name}') \ No newline at end of file diff --git a/src/test/resources/workspace/sample.camelk.js b/src/test/resources/workspace/sample.camelk.js deleted file mode 100644 index 5a196651..00000000 --- a/src/test/resources/workspace/sample.camelk.js +++ /dev/null @@ -1,5 +0,0 @@ -from('timer:js?period=1s') - .routeId('js') - .setBody() - .simple('Hello Camel K from ${routeId}') - .to('log:info?multiline=true') diff --git a/src/test/resources/workspace/sample.camelk.kts b/src/test/resources/workspace/sample.camelk.kts deleted file mode 100644 index 2ab41062..00000000 --- a/src/test/resources/workspace/sample.camelk.kts +++ /dev/null @@ -1,8 +0,0 @@ -from("timer:kotlin?period=1s") - .routeId("kotlin") - .setBody() - .constant("Hello Camel K!") - .process().message { - it.headers["RandomValue"] = rnd.nextInt() - } - .to("log:info?showAll=true&multiline=true") \ No newline at end of file diff --git a/src/test/resources/workspace/sampleWithModelineLike.js b/src/test/resources/workspace/sampleWithModelineLike.js deleted file mode 100644 index 9fda86d3..00000000 --- a/src/test/resources/workspace/sampleWithModelineLike.js +++ /dev/null @@ -1,7 +0,0 @@ -// camel-k: language=js - -from('timer:js?period=1s') - .routeId('js') - .setBody() - .simple('Hello Camel K from ${routeId}') - .to('log:info?multiline=true') diff --git a/src/test/resources/workspace/sampleWithModelineLike.kts b/src/test/resources/workspace/sampleWithModelineLike.kts deleted file mode 100644 index af05a0e5..00000000 --- a/src/test/resources/workspace/sampleWithModelineLike.kts +++ /dev/null @@ -1,10 +0,0 @@ -// camel-k: language=kotlin - -from("timer:kotlin?period=1s") - .routeId("kotlin") - .setBody() - .constant("Hello Camel K!") - .process().message { - it.headers["RandomValue"] = rnd.nextInt() - } - .to("log:info?showAll=true&multiline=true") \ No newline at end of file diff --git a/src/test/resources/workspace/samplewithModelineLike.groovy b/src/test/resources/workspace/samplewithModelineLike.groovy deleted file mode 100644 index 0a2c3074..00000000 --- a/src/test/resources/workspace/samplewithModelineLike.groovy +++ /dev/null @@ -1,6 +0,0 @@ -// camel-k: language=groovy - -from('direct:greeting-api') - .to('log:api?showAll=true&multiline=true') - .setBody() - .simple('Hello from ${headers.name}') \ No newline at end of file diff --git a/src/test/resources/workspace/samplewithshebang.groovy b/src/test/resources/workspace/samplewithshebang.groovy deleted file mode 100644 index 68abf77d..00000000 --- a/src/test/resources/workspace/samplewithshebang.groovy +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env camel-k - -from('direct:greeting-api') - .to('log:api?showAll=true&multiline=true') - .setBody() - .simple('Hello from ${headers.name}') \ No newline at end of file