@Test public void testCodeAction_exception() throws JavaModelException { URI uri = project.getFile("nopackage/Test.java").getRawLocationURI(); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri); try { cu.becomeWorkingCopy(new NullProgressMonitor()); CodeActionParams params = new CodeActionParams(); params.setTextDocument(new TextDocumentIdentifier(uri.toString())); final Range range = new Range(); range.setStart(new Position(0, 17)); range.setEnd(new Position(0, 17)); params.setRange(range); CodeActionContext context = new CodeActionContext(); context.setDiagnostics(Collections.emptyList()); params.setContext(context); List<? extends Command> commands = server.codeAction(params).join(); Assert.assertNotNull(commands); Assert.assertEquals(0, commands.size()); } finally { cu.discardWorkingCopy(); } }
private TextEdit change(final Position startPos, final Position endPos, final String newText) { TextEdit _textEdit = new TextEdit(); final Procedure1<TextEdit> _function = (TextEdit it) -> { if ((startPos != null)) { Range _range = new Range(); final Procedure1<Range> _function_1 = (Range it_1) -> { it_1.setStart(startPos); it_1.setEnd(endPos); }; Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1); it.setRange(_doubleArrow); } it.setNewText(newText); }; return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function); }
@Test public void testRangeFormattingService() { final Procedure1<RangeFormattingConfiguration> _function = (RangeFormattingConfiguration it) -> { StringConcatenation _builder = new StringConcatenation(); _builder.append("type Foo{int bar} type Bar{Foo foo}"); it.setModel(_builder.toString()); Range _range = new Range(); final Procedure1<Range> _function_1 = (Range it_1) -> { Position _position = new Position(0, 0); it_1.setStart(_position); Position _position_1 = new Position(0, 17); it_1.setEnd(_position_1); }; Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1); it.setRange(_doubleArrow); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("type Foo{"); _builder_1.newLine(); _builder_1.append("\t"); _builder_1.append("int bar"); _builder_1.newLine(); _builder_1.append("} type Bar{Foo foo}"); it.setExpectedText(_builder_1.toString()); }; this.testRangeFormatting(_function); }
public CompletableFuture<List<CompletionItem>> getCompletions(Position position) { if(textDocumentItem != null) { try { Node correspondingCamelNode = parserFileHelper.getCorrespondingCamelNodeForCompletion(textDocumentItem, position.getLine()); if (correspondingCamelNode != null) { String line = parserFileHelper.getLine(textDocumentItem, position); String camelComponentUri = parserFileHelper.getCamelComponentUri(textDocumentItem, position); CamelURIInstance camelURIInstance = new CamelURIInstance(camelComponentUri, correspondingCamelNode); int positionInCamelUri = position.getCharacter() - line.indexOf("uri=") - 5; CamelUriElementInstance camelUriElementInstance = camelURIInstance.getSpecificElement(positionInCamelUri); return camelUriElementInstance.getCompletions(camelCatalog, positionInCamelUri); } } catch (Exception e) { LOGGER.error("Error searching for corresponding node elements", e); } } return CompletableFuture.completedFuture(Collections.emptyList()); }
@Test public void testProvideDocumentationOnHover() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n"); TextDocumentPositionParams position = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI), new Position(0, 13)); CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(position); assertThat(hover.get().getContents().get(0).getLeft()).isEqualTo(AHC_DOCUMENTATION); }
@Test public void testChangeEventUpdatesStoredText() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n"); DidChangeTextDocumentParams changeEvent = new DidChangeTextDocumentParams(); VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(); textDocument.setUri(DUMMY_URI); changeEvent.setTextDocument(textDocument); TextDocumentContentChangeEvent contentChange = new TextDocumentContentChangeEvent("<to xmlns=\"http://camel.apache.org/schema/blueprint\" uri=\"\"></to>\n"); changeEvent.setContentChanges(Collections.singletonList(contentChange)); camelLanguageServer.getTextDocumentService().didChange(changeEvent); //check old position doesn't provide completion CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtOldPosition = getCompletionFor(camelLanguageServer, new Position(0, 11)); assertThat(completionsAtOldPosition.get().getLeft()).isEmpty(); //check new position provides completion CompletableFuture<Either<List<CompletionItem>, CompletionList>> completionsAtNewPosition = getCompletionFor(camelLanguageServer, new Position(0, 58)); assertThat(completionsAtNewPosition.get().getLeft()).isNotEmpty(); }
private static Optional<Location> findPath(TreePath path, Trees trees) { CompilationUnitTree compilationUnit = path.getCompilationUnit(); long start = trees.getSourcePositions().getStartPosition(compilationUnit, path.getLeaf()); long end = trees.getSourcePositions().getEndPosition(compilationUnit, path.getLeaf()); if (start == Diagnostic.NOPOS) return Optional.empty(); if (end == Diagnostic.NOPOS) end = start; int startLine = (int) compilationUnit.getLineMap().getLineNumber(start); int startColumn = (int) compilationUnit.getLineMap().getColumnNumber(start); int endLine = (int) compilationUnit.getLineMap().getLineNumber(end); int endColumn = (int) compilationUnit.getLineMap().getColumnNumber(end); return Optional.of( new Location( compilationUnit.getSourceFile().toUri().toString(), new Range( new Position(startLine - 1, startColumn - 1), new Position(endLine - 1, endColumn - 1)))); }
private SignatureHelp doHelp(String file, int row, int column) throws IOException { TextDocumentIdentifier document = new TextDocumentIdentifier(); document.setUri(FindResource.uri(file).toString()); Position position = new Position(); position.setLine(row - 1); position.setCharacter(column - 1); TextDocumentPositionParams p = new TextDocumentPositionParams(); p.setTextDocument(document); p.setPosition(position); try { return server.getTextDocumentService().signatureHelp(p).get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
@SuppressWarnings("restriction") private static Range convertRange(IProblem problem) { Position start = new Position(); Position end = new Position(); start.setLine(problem.getSourceLineNumber()-1);// VSCode is 0-based end.setLine(problem.getSourceLineNumber()-1); if(problem instanceof DefaultProblem){ DefaultProblem dProblem = (DefaultProblem)problem; start.setCharacter(dProblem.getSourceColumnNumber() - 1); int offset = 0; if (dProblem.getSourceStart() != -1 && dProblem.getSourceEnd() != -1) { offset = dProblem.getSourceEnd() - dProblem.getSourceStart() + 1; } end.setCharacter(dProblem.getSourceColumnNumber() - 1 + offset); } return new Range(start, end); }
private DocumentHighlight convertToHighlight(ITypeRoot unit, OccurrenceLocation occurrence) throws JavaModelException { DocumentHighlight h = new DocumentHighlight(); if ((occurrence.getFlags() | IOccurrencesFinder.F_WRITE_OCCURRENCE) == IOccurrencesFinder.F_WRITE_OCCURRENCE) { h.setKind(DocumentHighlightKind.Write); } else if ((occurrence.getFlags() | IOccurrencesFinder.F_READ_OCCURRENCE) == IOccurrencesFinder.F_READ_OCCURRENCE) { h.setKind(DocumentHighlightKind.Read); } int[] loc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset()); int[] endLoc = JsonRpcHelpers.toLine(unit.getBuffer(), occurrence.getOffset() + occurrence.getLength()); h.setRange(new Range( new Position(loc[0], loc[1]), new Position(endLoc[0],endLoc[1]) )); return h; }
@Test public void testReference(){ URI uri = project.getFile("src/java/Foo2.java").getRawLocationURI(); String fileURI = ResourceUtils.fixURI(uri); ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(5,16)); param.setContext(new ReferenceContext(true)); param.setTextDocument( new TextDocumentIdentifier(fileURI)); List<Location> references = handler.findReferences(param, monitor); assertNotNull("findReferences should not return null",references); assertEquals(1, references.size()); Location l = references.get(0); String refereeUri = ResourceUtils.fixURI(project.getFile("src/java/Foo3.java").getRawLocationURI()); assertEquals(refereeUri, l.getUri()); }
@Test public void testRenameSystemLibrary() throws JavaModelException { IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null); String[] codes = { "package test1;\n", "public class E {\n", " public int bar() {\n", " String str = new String();\n", " str.len|*gth();\n", " }\n", "}\n" }; StringBuilder builder = new StringBuilder(); Position pos = mergeCode(builder, codes); ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null); WorkspaceEdit edit = getRenameEdit(cu, pos, "newname"); assertNotNull(edit); assertEquals(edit.getChanges().size(), 0); }
@Test public void testHoverThrowable() throws Exception { String uriString = ClassFileUtil.getURI(project, "java.lang.Exception"); IClassFile classFile = JDTUtils.resolveClassFile(uriString); String contents = JavaLanguageServerPlugin.getContentProviderManager().getSource(classFile, monitor); IDocument document = new Document(contents); IRegion region = new FindReplaceDocumentAdapter(document).find(0, "Throwable", true, false, false, false); int offset = region.getOffset(); int line = document.getLineOfOffset(offset); int character = offset - document.getLineOffset(line); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uriString); Position position = new Position(line, character); TextDocumentPositionParams params = new TextDocumentPositionParams(textDocument, position); Hover hover = handler.hover(params, monitor); assertNotNull(hover); assertTrue("Unexpected hover ", !hover.getContents().isEmpty()); }
@Test public void testRangeFormatting() throws Exception { ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", //@formatter:off "package org.sample;\n" + " public class Baz {\n"+ "\tvoid foo(){\n" + " }\n"+ " }\n" //@formatter:on ); String uri = JDTUtils.toURI(unit); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri); Range range = new Range(new Position(2, 0), new Position(3, 5));// range around foo() DocumentRangeFormattingParams params = new DocumentRangeFormattingParams(range); params.setTextDocument(textDocument); params.setOptions(new FormattingOptions(3, true));// ident == 3 spaces List<? extends TextEdit> edits = server.rangeFormatting(params).get(); //@formatter:off String expectedText = "package org.sample;\n" + " public class Baz {\n"+ " void foo() {\n" + " }\n"+ " }\n"; //@formatter:on String newText = TextEditUtil.apply(unit, edits); assertEquals(expectedText, newText); }
@Test public void testCodeLens() { final Procedure1<AbstractLanguageServerTest.TestCodeLensConfiguration> _function = (AbstractLanguageServerTest.TestCodeLensConfiguration it) -> { StringConcatenation _builder = new StringConcatenation(); _builder.append("type Foo {}"); _builder.newLine(); _builder.append("type Bar {"); _builder.newLine(); _builder.append("\t"); _builder.append("Foo foo"); _builder.newLine(); _builder.append("}"); _builder.newLine(); it.setModel(_builder.toString()); final Procedure1<List<? extends CodeLens>> _function_1 = (List<? extends CodeLens> it_1) -> { this.assertEquals("Do Awesome Stuff(RESOLVED)", IterableExtensions.head(it_1).getCommand().getTitle()); Object _data = IterableExtensions.head(it_1).getData(); Assert.assertEquals(1, ((Position) _data).getLine()); }; it.setAssertCodeLenses(_function_1); }; this.testCodeLens(_function); }
protected void doTest(final String fileName, final Position position) { try { TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileName); final RenameParams params = new RenameParams(_textDocumentIdentifier, position, "Tescht"); final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get(); StringConcatenation _builder = new StringConcatenation(); _builder.append("changes :"); _builder.newLine(); _builder.append("\t"); _builder.append("MyType1.testlang : Tescht [[0, 5] .. [0, 9]]"); _builder.newLine(); _builder.append("\t"); _builder.append("Tescht [[1, 4] .. [1, 8]]"); _builder.newLine(); _builder.append("\t"); _builder.append("MyType2.testlang : Tescht [[1, 4] .. [1, 8]]"); _builder.newLine(); _builder.append("documentChanges : "); _builder.newLine(); this.assertEquals(_builder.toString(), this.toExpectation(workspaceEdit)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Test public void withoutNull() { Position _position = new Position(2, 2); Position _position_1 = new Position(2, 1); Position _position_2 = new Position(1, 2); Position _position_3 = new Position(1, 1); final List<? extends Position> input = this.sort(CollectionLiterals.<Position>newArrayList(_position, _position_1, _position_2, _position_3)); Assert.assertEquals(1, input.get(0).getLine()); Assert.assertEquals(1, input.get(0).getCharacter()); Assert.assertEquals(1, input.get(1).getLine()); Assert.assertEquals(2, input.get(1).getCharacter()); Assert.assertEquals(2, input.get(2).getLine()); Assert.assertEquals(1, input.get(2).getCharacter()); Assert.assertEquals(2, input.get(3).getLine()); Assert.assertEquals(2, input.get(3).getCharacter()); }
@Override public CompletableFuture<TestLangLSPExtension.TextOfLineResult> getTextOfLine(final TestLangLSPExtension.TextOfLineParam param) { final Function<ILanguageServerAccess.Context, TestLangLSPExtension.TextOfLineResult> _function = (ILanguageServerAccess.Context ctx) -> { Position _position = new Position(param.line, 0); final int start = ctx.getDocument().getOffSet(_position); Position _position_1 = new Position((param.line + 1), 0); int _offSet = ctx.getDocument().getOffSet(_position_1); int _length = System.lineSeparator().length(); final int end = (_offSet - _length); TestLangLSPExtension.TextOfLineResult _textOfLineResult = new TestLangLSPExtension.TextOfLineResult(); final Procedure1<TestLangLSPExtension.TextOfLineResult> _function_1 = (TestLangLSPExtension.TextOfLineResult it) -> { it.text = ctx.getDocument().getContents().substring(start, end); }; return ObjectExtensions.<TestLangLSPExtension.TextOfLineResult>operator_doubleArrow(_textOfLineResult, _function_1); }; return this.access.<TestLangLSPExtension.TextOfLineResult>doRead(param.uri, _function); }
@Test public void testRequest() throws Exception { TextDocumentPositionParams p = new TextDocumentPositionParams(); 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(); }
public Position getPosition(final int offset) { final int l = this.contents.length(); if (((offset < 0) || (offset > l))) { String _plus = (Integer.valueOf(offset) + " text was : "); String _plus_1 = (_plus + this.contents); throw new IndexOutOfBoundsException(_plus_1); } final char NL = '\n'; int line = 0; int column = 0; for (int i = 0; (i < l); i++) { { final char ch = this.contents.charAt(i); if ((i == offset)) { return new Position(line, column); } if ((ch == NL)) { line++; column = 0; } else { column++; } } } return new Position(line, column); }
@Test public void testDocumentResolve() throws Exception, ExecutionException { LanguageServer languageServer = wrap(LanguageServer.class, new MockLanguageServer() { @Override public CompletableFuture<DocumentLink> documentLinkResolve(DocumentLink params) { return CompletableFutures.computeAsync(canceler -> { params.setTarget("resolved"); return params; }); } }); CompletableFuture<DocumentLink> future = languageServer.getTextDocumentService().documentLinkResolve( new DocumentLink(new Range(new Position(0, 0), new Position(0, 0)), "unresolved") ); DocumentLink resolved = future.get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("resolved", resolved.getTarget()); }
@Test public void testEquals() { Assert.assertEquals(new TextDocumentIdentifier("foo"), new TextDocumentIdentifier("foo")); Assert.assertNotEquals(new TextDocumentIdentifier("foo"), new TextDocumentIdentifier("bar")); CompletionItem e1 = new CompletionItem(); e1.setAdditionalTextEdits(new ArrayList<>()); e1.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,1)), "foo")); CompletionItem e2 = new CompletionItem(); e2.setAdditionalTextEdits(new ArrayList<>()); e2.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,1)), "foo")); CompletionItem e3 = new CompletionItem(); e3.setAdditionalTextEdits(new ArrayList<>()); e3.getAdditionalTextEdits().add(new TextEdit(new Range(new Position(1,1), new Position(1,2)), "foo")); Assert.assertEquals(e1, e2); Assert.assertNotEquals(e1, e3); Assert.assertEquals(e1.hashCode(), e2.hashCode()); Assert.assertNotEquals(e1.hashCode(), e3.hashCode()); }
public String getLine(TextDocumentItem textDocumentItem, Position position) { String text = textDocumentItem.getText(); String[] lines = text.split("\\r?\\n", position.getLine() + 2); if (lines.length >= position.getLine() + 1) { return lines[position.getLine()]; } return null; }
public CompletableFuture<Hover> getHover(Position position) { try { ParserFileHelper parserFileHelper = new ParserFileHelper(); if(parserFileHelper.getCorrespondingCamelNodeForCompletion(textDocumentItem, position.getLine()) != null){ String camelComponentUri = parserFileHelper.getCamelComponentUri(textDocumentItem, position); String componentName = StringUtils.asComponentName(camelComponentUri); if (componentName != null) { return camelCatalog.thenApply(new HoverFuture(componentName)); } } } catch (Exception e) { LOGGER.error("Error searching hover", e); } return CompletableFuture.completedFuture(null); }
@Test public void testProvideCompletionForCamelBlueprintNamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11)); assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem); }
@Test public void testProvideCompletionForToCamelBlueprintNamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<to uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></to>\n"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 9)); assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem); }
@Test public void testProvideCompletionForCamelSpringNamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11)); assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem); }
@Test public void testProvideCompletionforMultiline() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer( "<camelContext xmlns=\"http://camel.apache.org/schema/spring\">\n" + "<to uri=\"\" ></to>\n" + "</camelContext>"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(1, 9)); assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem); }
@Test public void testDONTProvideCompletionForNotCamelnamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\"></from>\n"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11)); assertThat(completions.get().getLeft()).isEmpty(); assertThat(completions.get().getRight()).isNull(); }
@Test public void testDONTProvideCompletionWhenNotAfterURIEqualQuote() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n"); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 6)); assertThat(completions.get().getLeft()).isEmpty(); assertThat(completions.get().getRight()).isNull(); }
private void testProvideCamelOptions(String textTotest, int line, int character) throws URISyntaxException, InterruptedException, ExecutionException { CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character)); assertThat(completions.get().getLeft()).contains( new CompletionItem("true"), new CompletionItem("false")); }
@Test public void testProvideCompletionForCamelBlueprintNamespace() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer(textToTest); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character)); if(shouldHaveCompletion) { assertThat(completions.get().getLeft()).contains(expectedAhcCompletioncompletionItem); } else { assertThat(completions.get().getLeft()).doesNotContain(expectedAhcCompletioncompletionItem); assertThat(completions.get().getRight()).isNull(); } }
private void testProvideCamelOptions(String textTotest, int line, int character) throws URISyntaxException, InterruptedException, ExecutionException { CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(line, character)); assertThat(completions.get().getLeft()).contains( new CompletionItem("InOnly"), new CompletionItem("RobustInOnly"), new CompletionItem("InOut"), new CompletionItem("InOptionalOut"), new CompletionItem("OutOnly"), new CompletionItem("RobustOutOnly"), new CompletionItem("OutIn"), new CompletionItem("OutOptionalIn")); }
@Test public void testDontProvideDocumentationOnHoverForBadPlaces() throws Exception { CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"ahc:httpUri\" xmlns=\"http://camel.apache.org/schema/spring\"></from>\n"); TextDocumentPositionParams position = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI), new Position(0, 4)); CompletableFuture<Hover> hover = camelLanguageServer.getTextDocumentService().hover(position); assertThat(hover.get()).isNull(); }
protected CompletableFuture<Either<List<CompletionItem>, CompletionList>> getCompletionFor(CamelLanguageServer camelLanguageServer, Position position) { TextDocumentService textDocumentService = camelLanguageServer.getTextDocumentService(); TextDocumentPositionParams dummyCompletionPositionRequest = new TextDocumentPositionParams(new TextDocumentIdentifier(DUMMY_URI), position); CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = textDocumentService.completion(dummyCompletionPositionRequest); return completions; }
@NotNull private static Position getPosition(int pos, int[] lineStarts) { int line = Arrays.binarySearch(lineStarts, pos); if (line < 0) { int insertion_point = -1 * line - 1; line = insertion_point - 1; } return new Position(line, pos - lineStarts[line]); }
protected List<? extends CompletionItem> items(String file, int row, int column) { URI uri = FindResource.uri(file); TextDocumentPositionParams position = new TextDocumentPositionParams( new TextDocumentIdentifier(uri.toString()), uri.toString(), new Position(row - 1, column - 1)); try { return server.getTextDocumentService().completion(position).get().getRight().getItems(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } }
private static Position createPosition(IDocument document, int offset) { Position start = new Position(); try { int lineOfOffset = document.getLineOfOffset(offset); start.setLine( Integer.valueOf(lineOfOffset)); start.setCharacter(Integer.valueOf( offset - document.getLineOffset(lineOfOffset))); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return start; }
/** * @param marker * @return */ private static Range convertRange(IDocument document, IMarker marker) { int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; int cStart = 0; int cEnd = 0; try { //Buildship doesn't provide markers for gradle files, Maven does if (marker.isSubtypeOf(IMavenConstants.MARKER_ID)) { cStart = marker.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1); cEnd = marker.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1); } else { int lineOffset = 0; try { lineOffset = document.getLineOffset(line); } catch (BadLocationException unlikelyException) { JavaLanguageServerPlugin.logException(unlikelyException.getMessage(), unlikelyException); return new Range(new Position(line, 0), new Position(line, 0)); } cEnd = marker.getAttribute(IMarker.CHAR_END, -1) - lineOffset; cStart = marker.getAttribute(IMarker.CHAR_START, -1) - lineOffset; } } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } cStart = Math.max(0, cStart); cEnd = Math.max(0, cEnd); return new Range(new Position(line, cStart), new Position(line, cEnd)); }
@Test public void testEmpty(){ ReferenceParams param = new ReferenceParams(); param.setPosition(new Position(1, 1)); param.setContext(new ReferenceContext(false)); param.setTextDocument( new TextDocumentIdentifier("/foo/bar")); List<Location> references = handler.findReferences(param, monitor); assertNotNull(references); assertTrue("references are not empty", references.isEmpty()); }