Search in sources :

Example 71 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class CodeActionHandlerTest method testCodeAction_removeUnterminatedString.

@Test
public void testCodeAction_removeUnterminatedString() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + "	void foo() {\n" + "String s = \"some str\n" + "	}\n" + "}\n");
    CodeActionParams params = new CodeActionParams();
    params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
    final Range range = CodeActionUtil.getRange(unit, "some str");
    params.setRange(range);
    params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnterminatedString), range))));
    List<Either<Command, CodeAction>> codeActions = getCodeActions(params);
    Assert.assertNotNull(codeActions);
    Assert.assertFalse(codeActions.isEmpty());
    Assert.assertEquals(codeActions.get(0).getRight().getKind(), CodeActionKind.QuickFix);
    Command c = codeActions.get(0).getRight().getCommand();
    Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) AbstractQuickFixTest(org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest) Test(org.junit.Test)

Example 72 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class CodeActionHandlerTest method test_filterTypes.

@Test
public void test_filterTypes() throws Exception {
    // @formatter:off
    ICompilationUnit unit = getWorkingCopy("src/org/sample/Foo.java", "package org.sample;\n" + "\n" + "public class Foo {\n" + "	List foo;\n" + "}\n");
    // @formatter:on
    CodeActionParams params = new CodeActionParams();
    params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
    final Range range = CodeActionUtil.getRange(unit, "List");
    params.setRange(range);
    params.setContext(new CodeActionContext(Collections.emptyList()));
    List<Either<Command, CodeAction>> codeActions = getCodeActions(params);
    Assert.assertNotNull(codeActions);
    Assert.assertTrue("No organize imports action", containsKind(codeActions, CodeActionKind.SourceOrganizeImports));
    try {
        List<String> filteredTypes = new ArrayList<>();
        filteredTypes.add("java.util.*");
        PreferenceManager.getPrefs(null).setFilteredTypes(filteredTypes);
        codeActions = getCodeActions(params);
        assertNotNull(codeActions);
        Assert.assertFalse("No need for organize imports action", containsKind(codeActions, CodeActionKind.SourceOrganizeImports));
    } finally {
        PreferenceManager.getPrefs(null).setFilteredTypes(Collections.emptyList());
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) ArrayList(java.util.ArrayList) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Range(org.eclipse.lsp4j.Range) AbstractQuickFixTest(org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest) Test(org.junit.Test)

Example 73 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class InvisibleProjectBuildSupportTest method testUpdateReferencedLibraries.

@Test
public void testUpdateReferencedLibraries() throws Exception {
    IProject project = copyAndImportFolder("singlefile/simple", "src/App.java");
    NavigateToDefinitionHandler handler = new NavigateToDefinitionHandler(preferenceManager);
    String uri = ClassFileUtil.getURI(project, "App");
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
    List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(0, 13)), monitor);
    // The original mylib.jar is an empty jar, so the GTD is not available
    assertEquals(0, definitions.size());
    // replace it which contains the class 'mylib.A'
    IPath projectRealPath = ProjectUtils.getProjectRealFolder(project);
    IPath newLibPath = projectRealPath.append("mylib.jar");
    IPath referencedLibraryPath = projectRealPath.append("lib/mylib.jar");
    FileUtils.copyFile(newLibPath.toFile(), referencedLibraryPath.toFile());
    List<String> include = Arrays.asList("lib/**/*.jar");
    ReferencedLibraries libraries = new ReferencedLibraries(new HashSet<>(include));
    UpdateClasspathJob.getInstance().updateClasspath(JavaCore.create(project), libraries);
    waitForBackgroundJobs();
    definitions = handler.definition(new TextDocumentPositionParams(identifier, new Position(0, 13)), monitor);
    assertEquals(1, definitions.size());
}
Also used : ReferencedLibraries(org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) NavigateToDefinitionHandler(org.eclipse.jdt.ls.core.internal.handlers.NavigateToDefinitionHandler) IPath(org.eclipse.core.runtime.IPath) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test) HoverHandlerTest(org.eclipse.jdt.ls.core.internal.handlers.HoverHandlerTest)

Example 74 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project freemarker-languageserver by angelozerr.

the class FreemarkerTextDocumentService method didClose.

@Override
public void didClose(DidCloseTextDocumentParams params) {
    documents.onDidCloseTextDocument(params);
    fmDocuments.onDocumentRemoved(params.getTextDocument().getUri());
    TextDocumentIdentifier document = params.getTextDocument();
    String uri = document.getUri();
    fmLanguageServer.getLanguageClient().publishDiagnostics(new PublishDiagnosticsParams(uri, new ArrayList<Diagnostic>()));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ArrayList(java.util.ArrayList)

Example 75 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project ballerina by ballerina-lang.

the class CompletionTestUtil method getPositionParams.

/**
 * Get a new request message from the content.
 *
 * @param position position of the cursor
 * @param uri      documentURI
 * @return {@link TextDocumentPositionParams}
 */
public static TextDocumentPositionParams getPositionParams(Position position, String uri) {
    TextDocumentPositionParams textDocumentPositionParams = new TextDocumentPositionParams();
    TextDocumentIdentifier documentIdentifier = new TextDocumentIdentifier();
    documentIdentifier.setUri(Paths.get(uri).toUri().toString());
    textDocumentPositionParams.setPosition(position);
    textDocumentPositionParams.setTextDocument(documentIdentifier);
    return textDocumentPositionParams;
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Aggregations

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)172 Test (org.junit.Test)113 Position (org.eclipse.lsp4j.Position)102 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 Range (org.eclipse.lsp4j.Range)47 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)37 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)35 URI (java.net.URI)34 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)32 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)32 List (java.util.List)26 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Location (org.eclipse.lsp4j.Location)23 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)22 Command (org.eclipse.lsp4j.Command)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 CodeAction (org.eclipse.lsp4j.CodeAction)18