Java Code Examples for org.eclipse.lsp4j.CompletionItem#setDeprecated()

The following examples show how to use org.eclipse.lsp4j.CompletionItem#setDeprecated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotes() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInsideURI.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 46));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 46), new Position(12, 46)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 2
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotesInSingleQuotes() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInSingleQuotesInsideURI.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 47));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 47), new Position(12, 47)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 3
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingSingleQuotesInPlain() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithSingleQuotesInPlainInsideURI.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 45));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 45), new Position(12, 45)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 4
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotesInPlain() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInPlainInsideURI.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 45));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 45), new Position(12, 45)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 5
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotesInPlainUsingMoreSpaces() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInPlainInsideURIUsingMoreSpaces.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 50));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 50), new Position(12, 50)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 6
Source File: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Clones a {@link CompletionItem} for the given label from the supplied items
 *
 * @param targetLabel
 * @return a completion item
 */
private static CompletionItem cloneCompletionItem(List<CompletionItem> items, String targetLabel) {
    for (CompletionItem item : items) {
        if (item.getLabel().equalsIgnoreCase(targetLabel)) {
            CompletionItem clone = new CompletionItem(targetLabel);
            clone.setAdditionalTextEdits(item.getAdditionalTextEdits());
            clone.setCommand(item.getCommand());
            clone.setData(item.getData());
            clone.setDetail(item.getDetail());
            clone.setFilterText(item.getFilterText());
            clone.setInsertText(item.getInsertText());
            clone.setInsertTextFormat(item.getInsertTextFormat());
            clone.setDocumentation(item.getDocumentation());
            clone.setDeprecated(item.getDeprecated());
            clone.setKind(item.getKind());
            clone.setSortText(item.getSortText());
            clone.setPreselect(item.getPreselect());
            clone.setTextEdit(item.getTextEdit());
            return clone;
        }
    }
    return null;
}
 
Example 7
Source File: CamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testProvideCompletionForYamlOnRealFileWithCamelKCloseToModelineWithURIContainingDoubleQuotes() throws Exception {
	File f = new File("src/test/resources/workspace/samplewithModelineLikeWithDoubleQuotesInsideURI.yaml");
	assertThat(f).exists();
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer cls = initializeLanguageServer(fis, ".yaml");
		CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(cls, new Position(12, 47));
		CompletionItem expectedanyOrderAttributeCompletionItem = new CompletionItem("anyOrder");
		expectedanyOrderAttributeCompletionItem.setDocumentation("Whether the expected messages should arrive in the same order or can be in any order.");
		expectedanyOrderAttributeCompletionItem.setDeprecated(false);
		expectedanyOrderAttributeCompletionItem.setDetail("boolean");
		expectedanyOrderAttributeCompletionItem.setInsertText("anyOrder=false");
		expectedanyOrderAttributeCompletionItem.setTextEdit(new TextEdit(new Range(new Position(12, 47), new Position(12, 47)), "anyOrder=false"));
		assertThat(completions.get().getLeft()).contains(expectedanyOrderAttributeCompletionItem);
	}
}
 
Example 8
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private CompletionItem getBridgeEndpointExpectedCompletionItem(int startCharacter, int endCharacter) {
	CompletionItem completionItem = new CompletionItem("bridgeEndpoint");
	completionItem.setInsertText("bridgeEndpoint=false");
   	completionItem.setTextEdit(new TextEdit(new Range(new Position(0, startCharacter), new Position(0, endCharacter)), "bridgeEndpoint=false"));
   	completionItem.setDocumentation("If the option is true, then the Exchange.HTTP_URI header is ignored, and use the endpoint's URI for request. You may also set the throwExceptionOnFailure to be false to let the AhcProducer send all the fault response back.");
   	completionItem.setDetail("boolean");
   	completionItem.setDeprecated(false);
	return completionItem;
}
 
Example 9
Source File: CamelExtraComponentTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private CompletionItem createExpectedExtraComponentCompletionItem(int lineStart, int characterStart, int lineEnd, int characterEnd, String syntax, String description) {
	CompletionItem expectedAhcCompletioncompletionItem = new CompletionItem(syntax);
	expectedAhcCompletioncompletionItem.setDocumentation(description);
	expectedAhcCompletioncompletionItem.setDeprecated(false);
	expectedAhcCompletioncompletionItem.setTextEdit(new TextEdit(new Range(new Position(lineStart, characterStart), new Position(lineEnd, characterEnd)), syntax));
	return expectedAhcCompletioncompletionItem;
}
 
Example 10
Source File: AbstractCamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletionItem createExpectedAhcCompletionItem(int lineStart, int characterStart, int lineEnd, int characterEnd) {
	CompletionItem expectedAhcCompletioncompletionItem = new CompletionItem("ahc:httpUri");
	expectedAhcCompletioncompletionItem.setDocumentation(AHC_DOCUMENTATION);
	expectedAhcCompletioncompletionItem.setDeprecated(false);
	expectedAhcCompletioncompletionItem.setTextEdit(new TextEdit(new Range(new Position(lineStart, characterStart), new Position(lineEnd, characterEnd)), "ahc:httpUri"));
	return expectedAhcCompletioncompletionItem;
}
 
Example 11
Source File: CamelPropertiesComponentCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
protected CompletionItem createExpectedCompletionItem() {
	CompletionItem expectedCompletionItem = new CompletionItem("acomponent");
	expectedCompletionItem.setDocumentation("Description of my component.");
	expectedCompletionItem.setDeprecated(false);
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 16), new Position(0, 21)), "acomponent"));
	return expectedCompletionItem;
}
 
Example 12
Source File: CamelPropertiesComponentOptionNameCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testInsertAndReplace() throws Exception {
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = retrieveCompletion(new Position(0, 27), "camel.component.acomponent.awrongtoreplace=aValue");
	CompletionItem expectedCompletionItem = new CompletionItem("aComponentProperty");
	expectedCompletionItem.setInsertText("aComponentProperty");
	expectedCompletionItem.setDocumentation("A parameter description");
	expectedCompletionItem.setDeprecated(false);
	expectedCompletionItem.setDetail(String.class.getName());
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 27), new Position(0, 42)), "aComponentProperty"));
	assertThat(completions.get().getLeft()).contains(expectedCompletionItem);
}
 
Example 13
Source File: CamelPropertiesComponentOptionNameCompletionTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCompletionWithoutDefaultValueIfAValueAlreadyProvided() throws Exception {
	CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = retrieveCompletion(new Position(0, 27), "camel.component.acomponent.aComponentProperty=aValue");
	CompletionItem expectedCompletionItem = new CompletionItem("aComponentProperty");
	expectedCompletionItem.setInsertText("aComponentProperty");
	expectedCompletionItem.setDocumentation("A parameter description");
	expectedCompletionItem.setDeprecated(false);
	expectedCompletionItem.setDetail(String.class.getName());
	expectedCompletionItem.setTextEdit(new TextEdit(new Range(new Position(0, 27), new Position(0, 45)), "aComponentProperty"));
	assertThat(completions.get().getLeft()).contains(expectedCompletionItem);
}
 
Example 14
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCamelOptionsForConsumerOrProducer() throws Exception {
   	CompletionItem completionItem = new CompletionItem("clientConfigOptions");
   	completionItem.setInsertText("clientConfigOptions=");
   	completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 23), new Position(0, 23)), "clientConfigOptions="));
   	completionItem.setDocumentation("To configure the AsyncHttpClientConfig using the key/values from the Map.");
   	completionItem.setDetail("java.util.Map<java.lang.String, java.lang.Object>");
   	completionItem.setDeprecated(false);
	testProvideCamelOptions("<from uri=\"ahc:httpUri?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 23, completionItem);
}
 
Example 15
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCamelOptionsForConsumerOnlyForJava() throws Exception {
   	CompletionItem completionItem = new CompletionItem("bridgeErrorHandler");
   	completionItem.setInsertText("bridgeErrorHandler=false");
   	completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 22), new Position(0, 22)), "bridgeErrorHandler=false"));
   	completionItem.setDocumentation("Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.");
   	completionItem.setDetail("boolean");
   	completionItem.setDeprecated(false);
	testProvideCamelOptions("from(\"timer:timerName?\")//camel", 0, 22, completionItem, ".java");
}
 
Example 16
Source File: CamelComponentOptionsCompletionsTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testProvideCamelOptionsForConsumerOnly() throws Exception {
   	CompletionItem completionItem = new CompletionItem("bridgeErrorHandler");
   	completionItem.setInsertText("bridgeErrorHandler=false");
   	completionItem.setTextEdit(new TextEdit(new Range(new Position(0, 27), new Position(0, 27)), "bridgeErrorHandler=false"));
   	completionItem.setDocumentation("Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.");
   	completionItem.setDetail("boolean");
   	completionItem.setDeprecated(false);
	testProvideCamelOptions("<from uri=\"timer:timerName?\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n", 0, 27, completionItem);
}
 
Example 17
Source File: DdlCompletionItemLoader.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
    private List<CompletionItem> loadItemsFromFile(String fileName) {
        List<CompletionItem> items = new ArrayList<CompletionItem>();

        try (InputStream stream = this.getClass().getResourceAsStream(fileName)) {
            JSONParser parser = new JSONParser(stream);

            // A JSON object. Key value pairs are unordered. JSONObject supports
            // java.util.Map interface.
            LinkedHashMap<String, Object> jsonObject = parser.object();

            // A JSON array. JSONObject supports java.util.List interface.
            ArrayList<?> completionItemArray = (ArrayList<?>) jsonObject.get("items");

            if (completionItemArray != null) {
                for (Object item : completionItemArray) {
                    LinkedHashMap<String, Object> itemInfo = (LinkedHashMap<String, Object>) item;
                    CompletionItem newItem = new CompletionItem();
                    newItem.setLabel((String) itemInfo.get("label"));
                    newItem.setKind(STRING_TO_KIND_MAP.get(((String) itemInfo.get("kind")).toUpperCase(Locale.US)));

                    String detail = (String) itemInfo.get("detail");
                    if (detail != null) {
                        newItem.setDetail(detail);
                    }

                    String documentation = (String) itemInfo.get("documentation");
                    if (documentation != null) {
                        newItem.setDocumentation(documentation);
                    }

                    newItem.setDeprecated(Boolean.parseBoolean((String) itemInfo.get("deprecated")));
                    newItem.setPreselect(Boolean.parseBoolean((String) itemInfo.get("preselect")));

                    String sortText = (String) itemInfo.get("sortText");
                    if (sortText != null) {
                        newItem.setSortText(sortText);
                    }

                    String insertText = (String) itemInfo.get("insertText");
                    if (insertText != null) {
                        insertText = insertText.replaceAll("\\n", "\n");
                        insertText = insertText.replaceAll("\\t", "\t");
                        newItem.setInsertText(insertText);
                    }

                    String insertTextFormat = (String) itemInfo.get("insertTextFormat");
                    if (insertTextFormat != null) {
                        if (newItem.getKind().equals(CompletionItemKind.Snippet)) {
                            newItem.setInsertTextFormat(InsertTextFormat.Snippet);
                        } else {
                            newItem.setInsertTextFormat(InsertTextFormat.PlainText);
                        }
                    }
                    // TODO: Implement quick fixes
//                  newItem.setTextEdit((TextEdit)itemInfo.get("textEdit"));
//                  newItem.setAdditionalTextEdits((List<TextEdit>)itemInfo.get("additionalTextEdits"));
//                  newItem.setCommitCharacters((List<String>)itemInfo.get("commitCharacters"));

                    String category = (String) itemInfo.get("category");
                    if (category != null && !category.isEmpty()) {
                        addItemByCategory(category, newItem);
                    } else {
                        items.add(newItem);
                    }
                }
            }

        } catch (IOException | ParseException e) {
            throw new IllegalArgumentException("Unable to parse given file: " + fileName, e);
        }

        return items;
    }
 
Example 18
Source File: CompletionProvider.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
private void addDefinitionAutoCompleteActionScript(IDefinition definition, IASNode offsetNode, char nextChar, AddImportData addImportData, ILspProject project, CompletionList result)
{
    String definitionBaseName = definition.getBaseName();
    if (definitionBaseName.length() == 0)
    {
        //vscode expects all items to have a name
        return;
    }
    if (definitionBaseName.startsWith(VECTOR_HIDDEN_PREFIX))
    {
        return;
    }
    if (isDuplicateTypeDefinition(definition))
    {
        return;
    }
    if (definition instanceof ITypeDefinition)
    {
        String qualifiedName = definition.getQualifiedName();
        completionTypes.add(qualifiedName);
    }
    CompletionItem item = CompletionItemUtils.createDefinitionItem(definition, project);
    if (definition instanceof IFunctionDefinition
            && !(definition instanceof IAccessorDefinition)
            && nextChar != '('
            && completionSupportsSnippets)
    {
        IFunctionDefinition functionDefinition = (IFunctionDefinition) definition;
        if (functionDefinition.getParameters().length == 0)
        {
            item.setInsertText(definition.getBaseName() + "()");
        }
        else
        {
            item.setInsertTextFormat(InsertTextFormat.Snippet);
            item.setInsertText(definition.getBaseName() + "($0)");
            Command showParamsCommand = new Command();
            showParamsCommand.setCommand("editor.action.triggerParameterHints");
            item.setCommand(showParamsCommand);
        }
    }
    if (ASTUtils.needsImport(offsetNode, definition.getQualifiedName()))
    {
        TextEdit textEdit = CodeActionsUtils.createTextEditForAddImport(definition, addImportData);
        if(textEdit != null)
        {
            item.setAdditionalTextEdits(Collections.singletonList(textEdit));
        }
    }
    IDeprecationInfo deprecationInfo = definition.getDeprecationInfo();
    if (deprecationInfo != null)
    {
        item.setDeprecated(true);
    }
    result.getItems().add(item);
}