Java Code Examples for org.eclipse.lsp4j.TextDocumentIdentifier#setUri()
The following examples show how to use
org.eclipse.lsp4j.TextDocumentIdentifier#setUri() .
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: SaveActionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testWillSaveWaitUntil() throws Exception { URI srcUri = project.getFile("src/java/Foo4.java").getRawLocationURI(); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(srcUri); StringBuilder buf = new StringBuilder(); buf.append("package java;\n"); buf.append("\n"); buf.append("public class Foo4 {\n"); buf.append("}\n"); WillSaveTextDocumentParams params = new WillSaveTextDocumentParams(); TextDocumentIdentifier document = new TextDocumentIdentifier(); document.setUri(srcUri.toString()); params.setTextDocument(document); List<TextEdit> result = handler.willSaveWaitUntil(params, monitor); Document doc = new Document(); doc.set(cu.getSource()); assertEquals(TextEditUtil.apply(doc, result), buf.toString()); }
Example 2
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
protected List<Either<Command, CodeAction>> getCodeActions(ICompilationUnit cu) throws JavaModelException { CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null); IProblem[] problems = astRoot.getProblems(); Range range = getRange(cu, problems); CodeActionParams parms = new CodeActionParams(); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(cu)); parms.setTextDocument(textDocument); parms.setRange(range); CodeActionContext context = new CodeActionContext(); context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems), true)); context.setOnly(Arrays.asList(CodeActionKind.QuickFix)); parms.setContext(context); return new CodeActionHandler(this.preferenceManager).getCodeActionCommands(parms, new NullProgressMonitor()); }
Example 3
Source File: LSPIJUtils.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
private static <T extends TextDocumentPositionParams> T toTextDocumentPositionParamsCommon(T param, int offset, Document document) { URI uri = toUri(document); Position start = toPosition(offset, document); param.setPosition(start); TextDocumentIdentifier id = new TextDocumentIdentifier(); if (uri != null) { param.setUri(uri.toString()); id.setUri(uri.toString()); } param.setTextDocument(id); return param; }
Example 4
Source File: LSPIJUtils.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
public static CompletionParams toCompletionParams(URI fileUri, int offset, Document document) { Position start = toPosition(offset, document); CompletionParams param = new CompletionParams(); param.setPosition(start); param.setUri(fileUri.toString()); TextDocumentIdentifier id = new TextDocumentIdentifier(); id.setUri(fileUri.toString()); param.setTextDocument(id); return param; }
Example 5
Source File: AbstractCodeActionTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected void performTest(Project project, String moduleName, N4JSTestCodeActionConfiguration tcac) throws InterruptedException, ExecutionException { CodeActionParams codeActionParams = new CodeActionParams(); Range range = new Range(); Position posStart = new Position(tcac.getLine(), tcac.getColumn()); Position posEnd = tcac.getEndLine() >= 0 && tcac.getEndColumn() >= 0 ? new Position(tcac.getEndLine(), tcac.getEndColumn()) : posStart; range.setStart(posStart); range.setEnd(posEnd); codeActionParams.setRange(range); CodeActionContext context = new CodeActionContext(); FileURI uri = getFileURIFromModuleName(moduleName); context.setDiagnostics(Lists.newArrayList(getIssues(uri))); codeActionParams.setContext(context); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(uri.toString()); codeActionParams.setTextDocument(textDocument); CompletableFuture<List<Either<Command, CodeAction>>> future = languageServer.codeAction(codeActionParams); List<Either<Command, CodeAction>> result = future.get(); if (tcac.getAssertCodeActions() != null) { tcac.getAssertCodeActions().apply(result); } else { String resultStr = result.stream() .map(cmdOrAction -> getStringLSP4J().toString3(cmdOrAction)) .collect(Collectors.joining("\n-----\n")); assertEquals(tcac.getExpectedCodeActions().trim(), resultStr.trim()); } }
Example 6
Source File: AbstractCompletionTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
@Override protected void performTest(Project project, String moduleName, TestCompletionConfiguration tcc) throws InterruptedException, ExecutionException { CompletionParams completionParams = new CompletionParams(); Position pos = new Position(tcc.getLine(), tcc.getColumn()); completionParams.setPosition(pos); FileURI uri = getFileURIFromModuleName(tcc.getFilePath()); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(uri.toString()); completionParams.setTextDocument(textDocument); CompletableFuture<Either<List<CompletionItem>, CompletionList>> future = languageServer .completion(completionParams); Either<List<CompletionItem>, CompletionList> result = future.get(); List<CompletionItem> items = result.isLeft() ? result.getLeft() : result.getRight().getItems(); // assert already sorted List<CompletionItem> sortedItems = ListExtensions.sortInplaceBy(items, CompletionItem::getSortText); Assert.assertEquals(items, sortedItems); if (tcc.getAssertCompletionList() != null) { tcc.getAssertCompletionList().apply(result.getRight()); } else { String resultStr = Strings.join("\n", getStringLSP4J()::toString, items); assertEquals(tcc.getExpectedCompletionItems().trim(), resultStr.trim()); } }
Example 7
Source File: SaveActionHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testStaticWillSaveWaitUntil() throws Exception { String[] favourites = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getJavaCompletionFavoriteMembers(); try { List<String> list = new ArrayList<>(); list.add("java.lang.Math.*"); list.add("java.util.stream.Collectors.*"); JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setJavaCompletionFavoriteMembers(list); URI srcUri = project.getFile("src/org/sample/Foo6.java").getRawLocationURI(); ICompilationUnit cu = JDTUtils.resolveCompilationUnit(srcUri); /* @formatter:off */ String expected = "package org.sample;\n" + "\n" + "import static java.lang.Math.PI;\n" + "import static java.lang.Math.abs;\n" + "import static java.util.stream.Collectors.toList;\n" + "\n" + "import java.util.List;\n" + "\n" + "public class Foo6 {\n" + " List list = List.of(1).stream().collect(toList());\n" + " double i = abs(-1);\n" + " double pi = PI;\n" + "}\n"; //@formatter:on WillSaveTextDocumentParams params = new WillSaveTextDocumentParams(); TextDocumentIdentifier document = new TextDocumentIdentifier(); document.setUri(srcUri.toString()); params.setTextDocument(document); List<TextEdit> result = handler.willSaveWaitUntil(params, monitor); Document doc = new Document(); doc.set(cu.getSource()); assertEquals(expected, TextEditUtil.apply(doc, result)); } finally { JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setJavaCompletionFavoriteMembers(Arrays.asList(favourites)); } }
Example 8
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void saveDocument(ICompilationUnit cu) throws Exception { DidSaveTextDocumentParams saveParms = new DidSaveTextDocumentParams(); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(cu)); saveParms.setTextDocument(textDocument); saveParms.setText(cu.getSource()); lifeCycleHandler.didSave(saveParms); waitForBackgroundJobs(); }
Example 9
Source File: DocumentLifeCycleHandlerTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void closeDocument(ICompilationUnit cu) { DidCloseTextDocumentParams closeParms = new DidCloseTextDocumentParams(); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(cu)); closeParms.setTextDocument(textDocument); lifeCycleHandler.didClose(closeParms); }
Example 10
Source File: NonProjectFixTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private List<Either<Command, CodeAction>> getCodeActions(ICompilationUnit cu, IProblem problem) throws JavaModelException { CodeActionParams parms = new CodeActionParams(); Range range = JDTUtils.toRange(cu, problem.getSourceStart(), 0); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(); textDocument.setUri(JDTUtils.toURI(cu)); parms.setTextDocument(textDocument); parms.setRange(range); CodeActionContext context = new CodeActionContext(); context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problem), true)); context.setOnly(Arrays.asList(CodeActionKind.QuickFix)); parms.setContext(context); return new CodeActionHandler(this.preferenceManager).getCodeActionCommands(parms, new NullProgressMonitor()); }