Java Code Examples for org.eclipse.lsp4j.CompletionItem#setInsertText()
The following examples show how to use
org.eclipse.lsp4j.CompletionItem#setInsertText() .
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 |
@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 2
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@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 3
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@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 4
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@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 5
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@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 6
Source File: CamelLanguageServerTest.java From camel-language-server with Apache License 2.0 | 6 votes |
@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 7
Source File: CompletionItemBuilder.java From syndesis with Apache License 2.0 | 6 votes |
public CompletionItem createSnippetItem(String label, String detail, String documentation, String insertText) { CompletionItem ci = new CompletionItem(); ci.setLabel(label); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setInsertText(insertText); if (documentation != null) { ci.setDocumentation(documentation); } else { ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); } if (detail != null) { ci.setDetail(detail); } return ci; }
Example 8
Source File: LauncherTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testRequest() throws Exception { CompletionParams p = new CompletionParams(); p.setPosition(new Position(1,1)); p.setTextDocument(new TextDocumentIdentifier("test/foo.txt")); CompletionList result = new CompletionList(); result.setIsIncomplete(true); result.setItems(new ArrayList<>()); CompletionItem item = new CompletionItem(); item.setDetail("test"); item.setDocumentation("doc"); item.setFilterText("filter"); item.setInsertText("insert"); item.setKind(CompletionItemKind.Field); result.getItems().add(item); server.expectedRequests.put("textDocument/completion", new Pair<>(p, result)); CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = clientLauncher.getRemoteProxy().getTextDocumentService().completion(p); Assert.assertEquals(Either.forRight(result).toString(), future.get(TIMEOUT, TimeUnit.MILLISECONDS).toString()); client.joinOnEmpty(); }
Example 9
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
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 10
Source File: TableBodyCompletionProvider.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getQueryExpressionSnippet(int data) { CompletionItem ci = new CompletionItem(); ci.setLabel("AS SELECT * FROM ..."); ci.setInsertText(" AS SELECT * FROM ${4:table_name};"); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); return ci; }
Example 11
Source File: CompletionProposalRequestor.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private void adjustCompleteItem(CompletionItem item) { if (item.getKind() == CompletionItemKind.Function) { String text = item.getInsertText(); if (StringUtils.isNotBlank(text) && !text.endsWith(")")) { item.setInsertText(text + "()"); } } }
Example 12
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createSimpleLabelWithType(CompletionProposal proposal, CompletionItem item) { StringBuilder nameBuffer= new StringBuilder(); nameBuffer.append(proposal.getCompletion()); item.setInsertText(nameBuffer.toString()); char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature()); if (typeName.length > 0) { nameBuffer.append(VAR_TYPE_SEPARATOR); nameBuffer.append(typeName); } item.setLabel(nameBuffer.toString()); }
Example 13
Source File: CamelPropertiesComponentOptionNameCompletionTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@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 14
Source File: DdlCompletionItemLoader.java From syndesis with Apache License 2.0 | 5 votes |
public CompletionItem getCreateViewUnionCompletionItem(int data, String sortValue) { CompletionItem ci = new CompletionItem(); ci.setLabel("CREATE VIEW with UNION"); ci.setInsertText(QueryExpressionHelper.CREATE_VIEW_UNION_INSERT_TEXT); ci.setKind(CompletionItemKind.Snippet); ci.setInsertTextFormat(InsertTextFormat.Snippet); ci.setDetail(" Union of two tables from single source"); ci.setDocumentation(CompletionItemBuilder.beautifyDocument(ci.getInsertText())); ci.setData(data); ci.setPreselect(true); ci.setSortText(sortValue); return ci; }
Example 15
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@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 16
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@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 17
Source File: CamelComponentOptionsCompletionsTest.java From camel-language-server with Apache License 2.0 | 5 votes |
@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 18
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
private void addEventMetadataToAutoCompleteMXML(TypeScope typeScope, boolean isAttribute, String prefix, boolean includeOpenTagBracket, boolean includeOpenTagPrefix, char nextChar, ILspProject project, CompletionList result) { ArrayList<String> eventNames = new ArrayList<>(); IDefinition definition = typeScope.getDefinition(); while (definition instanceof IClassDefinition) { IClassDefinition classDefinition = (IClassDefinition) definition; IMetaTag[] eventMetaTags = definition.getMetaTagsByName(IMetaAttributeConstants.ATTRIBUTE_EVENT); for (IMetaTag eventMetaTag : eventMetaTags) { String eventName = eventMetaTag.getAttributeValue(IMetaAttributeConstants.NAME_EVENT_NAME); if (eventName == null || eventName.length() == 0) { //vscode expects all items to have a name continue; } if (eventNames.contains(eventName)) { //avoid duplicates! continue; } eventNames.add(eventName); IDefinition eventDefinition = project.resolveSpecifier(classDefinition, eventName); if (eventDefinition == null) { continue; } CompletionItem item = CompletionItemUtils.createDefinitionItem(eventDefinition, project); if (isAttribute && completionSupportsSnippets && nextChar != '=') { item.setInsertTextFormat(InsertTextFormat.Snippet); item.setInsertText(eventName + "=\"$0\""); } else if (!isAttribute) { StringBuilder builder = new StringBuilder(); if (includeOpenTagBracket) { builder.append("<"); } if(includeOpenTagPrefix && prefix != null && prefix.length() > 0) { builder.append(prefix); builder.append(IMXMLCoreConstants.colon); } builder.append(eventName); if (completionSupportsSnippets) { item.setInsertTextFormat(InsertTextFormat.Snippet); builder.append(">"); builder.append("$0"); builder.append("</"); if(prefix != null && prefix.length() > 0) { builder.append(prefix); builder.append(IMXMLCoreConstants.colon); } builder.append(eventName); builder.append(">"); } item.setInsertText(builder.toString()); } result.getItems().add(item); } definition = classDefinition.resolveBaseClass(project); } }
Example 19
Source File: SnippetCompletionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static List<CompletionItem> getGenericSnippets(SnippetCompletionContext scc) throws JavaModelException { List<CompletionItem> res = new ArrayList<>(); CompletionContext completionContext = scc.getCompletionContext(); char[] completionToken = completionContext.getToken(); if (completionToken == null) { return Collections.emptyList(); } int tokenLocation = completionContext.getTokenLocation(); JavaContextType contextType = (JavaContextType) JavaLanguageServerPlugin.getInstance().getTemplateContextRegistry().getContextType(JavaContextType.ID_STATEMENTS); if (contextType == null) { return Collections.emptyList(); } ICompilationUnit cu = scc.getCompilationUnit(); IDocument document = new Document(cu.getSource()); DocumentTemplateContext javaContext = contextType.createContext(document, completionContext.getOffset(), completionToken.length, cu); Template[] templates = null; if ((tokenLocation & CompletionContext.TL_STATEMENT_START) != 0) { templates = JavaLanguageServerPlugin.getInstance().getTemplateStore().getTemplates(JavaContextType.ID_STATEMENTS); } else { // We only support statement templates for now. } if (templates == null || templates.length == 0) { return Collections.emptyList(); } for (Template template : templates) { if (!javaContext.canEvaluate(template)) { continue; } TemplateBuffer buffer = null; try { buffer = javaContext.evaluate(template); } catch (BadLocationException | TemplateException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); continue; } if (buffer == null) { continue; } String content = buffer.getString(); if (Strings.containsOnlyWhitespaces(content)) { continue; } final CompletionItem item = new CompletionItem(); item.setLabel(template.getName()); item.setInsertText(content); item.setDetail(template.getDescription()); setFields(item, cu); res.add(item); } return res; }
Example 20
Source File: CompletionProvider.java From vscode-as3mxml with Apache License 2.0 | 4 votes |
private void addLanguageAttributesToAutoCompleteMXML(TypeScope typeScope, ASScope otherScope, char nextChar, ILspProject project, CompletionList result) { List<CompletionItem> items = result.getItems(); CompletionItem includeInItem = new CompletionItem(); includeInItem.setKind(CompletionItemKind.Keyword); includeInItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_INCLUDE_IN); if (completionSupportsSnippets && nextChar != '=') { includeInItem.setInsertTextFormat(InsertTextFormat.Snippet); includeInItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_INCLUDE_IN + "=\"$0\""); } items.add(includeInItem); CompletionItem excludeFromItem = new CompletionItem(); excludeFromItem.setKind(CompletionItemKind.Keyword); excludeFromItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_EXCLUDE_FROM); if (completionSupportsSnippets && nextChar != '=') { excludeFromItem.setInsertTextFormat(InsertTextFormat.Snippet); excludeFromItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_EXCLUDE_FROM + "=\"$0\""); } items.add(excludeFromItem); Set<INamespaceDefinition> namespaceSet = ScopeUtils.getNamespaceSetForScopes(typeScope, otherScope, project); IDefinition idPropertyDefinition = typeScope.getPropertyByNameForMemberAccess((CompilerProject) project, IMXMLLanguageConstants.ATTRIBUTE_ID, namespaceSet); if (idPropertyDefinition == null) { CompletionItem idItem = new CompletionItem(); idItem.setKind(CompletionItemKind.Keyword); idItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_ID); if (completionSupportsSnippets && nextChar != '=') { idItem.setInsertTextFormat(InsertTextFormat.Snippet); idItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_ID + "=\"$0\""); } items.add(idItem); } if (frameworkSDKIsRoyale) { IDefinition localIdPropertyDefinition = typeScope.getPropertyByNameForMemberAccess((CompilerProject) project, IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID, namespaceSet); if (localIdPropertyDefinition == null) { CompletionItem localIdItem = new CompletionItem(); localIdItem.setKind(CompletionItemKind.Keyword); localIdItem.setLabel(IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID); if (completionSupportsSnippets && nextChar != '=') { localIdItem.setInsertTextFormat(InsertTextFormat.Snippet); localIdItem.setInsertText(IMXMLLanguageConstants.ATTRIBUTE_LOCAL_ID + "=\"$0\""); } items.add(localIdItem); } } }