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());
}
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());
}
}
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());
}
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>()));
}
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;
}
Aggregations