org.eclipse.lsp4j.WorkspaceEditCapabilities Java Examples

The following examples show how to use org.eclipse.lsp4j.WorkspaceEditCapabilities. 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: LanguageServerWrapper.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
private InitializeParams getInitParams() {
    InitializeParams initParams = new InitializeParams();
    initParams.setRootUri(FileUtils.pathToUri(projectRootPath));
    //TODO update capabilities when implemented
    WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
    workspaceClientCapabilities.setApplyEdit(true);
    workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities());
    workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities());
    workspaceClientCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
    workspaceClientCapabilities.setSymbol(new SymbolCapabilities());
    workspaceClientCapabilities.setWorkspaceFolders(false);
    workspaceClientCapabilities.setConfiguration(false);

    TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
    textDocumentClientCapabilities.setCodeAction(new CodeActionCapabilities());
    textDocumentClientCapabilities.setCompletion(new CompletionCapabilities(new CompletionItemCapabilities(true)));
    textDocumentClientCapabilities.setDefinition(new DefinitionCapabilities());
    textDocumentClientCapabilities.setDocumentHighlight(new DocumentHighlightCapabilities());
    textDocumentClientCapabilities.setFormatting(new FormattingCapabilities());
    textDocumentClientCapabilities.setHover(new HoverCapabilities());
    textDocumentClientCapabilities.setOnTypeFormatting(new OnTypeFormattingCapabilities());
    textDocumentClientCapabilities.setRangeFormatting(new RangeFormattingCapabilities());
    textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
    textDocumentClientCapabilities.setRename(new RenameCapabilities());
    textDocumentClientCapabilities.setSemanticHighlightingCapabilities(new SemanticHighlightingCapabilities(false));
    textDocumentClientCapabilities.setSignatureHelp(new SignatureHelpCapabilities());
    textDocumentClientCapabilities.setSynchronization(new SynchronizationCapabilities(true, true, true));
    initParams.setCapabilities(
            new ClientCapabilities(workspaceClientCapabilities, textDocumentClientCapabilities, null));
    initParams.setInitializationOptions(
            serverDefinition.getInitializationOptions(URI.create(initParams.getRootUri())));

    return initParams;
}
 
Example #2
Source File: XMLSchemaDiagnosticsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void localSchemaFileMissingCodeAction() throws Exception {
	String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //
			"<invoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //
			"  xsi:noNamespaceSchemaLocation=\"/salad.xsd\">\n" + //
			"</invoice>";
	Diagnostic missingSchemaDiagnostic = d(2, 32, 44, XMLSchemaErrorCode.schema_reference_4);
	missingSchemaDiagnostic.setMessage("schema_reference.4: Failed to read schema document "
			+ "'file:///salad.xsd',"
			+ " because 1) could not find the document; 2) the document could not be read;"
			+ " 3) the root element of the document is not <xsd:schema>.");
	Diagnostic eltDiagnostic = d(1, 1, 8, XMLSchemaErrorCode.cvc_elt_1_a);
	eltDiagnostic.setMessage("cvc-elt.1.a: Cannot find the declaration of element 'invoice'.");
	XMLAssert.testDiagnosticsFor(xml, missingSchemaDiagnostic, eltDiagnostic);

	SharedSettings settings = new SharedSettings();
	WorkspaceClientCapabilities workspace = new WorkspaceClientCapabilities();
	WorkspaceEditCapabilities workspaceEdit = new WorkspaceEditCapabilities();
	workspaceEdit.setResourceOperations(Arrays.asList(ResourceOperationKind.Create));
	workspace.setWorkspaceEdit(workspaceEdit);
	settings.getWorkspaceSettings().setCapabilities(workspace);

	XMLAssert.testCodeActionsFor(xml, //
			missingSchemaDiagnostic, //
			settings, //
			ca(missingSchemaDiagnostic, //
					createFile("file:///salad.xsd", false), //
					teOp("file:///salad.xsd", 0, 0, 0, 0, //
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + lineSeparator() + //
									"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">" + lineSeparator() + //
									"  <xs:element name=\"invoice\" type=\"xs:string\" />" + lineSeparator() + //
									"</xs:schema>")));
}
 
Example #3
Source File: LSPBindings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static InitializeResult initServer(Process p, LanguageServer server, FileObject root) throws InterruptedException, ExecutionException {
   InitializeParams initParams = new InitializeParams();
   initParams.setRootUri(Utils.toURI(root));
   initParams.setRootPath(FileUtil.toFile(root).getAbsolutePath()); //some servers still expect root path
   initParams.setProcessId(0);
   TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities();
   DocumentSymbolCapabilities dsc = new DocumentSymbolCapabilities();
   dsc.setHierarchicalDocumentSymbolSupport(true);
   dsc.setSymbolKind(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values())));
   tdcc.setDocumentSymbol(dsc);
   WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
   wcc.setWorkspaceEdit(new WorkspaceEditCapabilities());
   wcc.getWorkspaceEdit().setDocumentChanges(true);
   wcc.getWorkspaceEdit().setResourceOperations(Arrays.asList(ResourceOperationKind.Create, ResourceOperationKind.Delete, ResourceOperationKind.Rename));
   initParams.setCapabilities(new ClientCapabilities(wcc, tdcc, null));
   CompletableFuture<InitializeResult> initResult = server.initialize(initParams);
   while (true) {
       try {
           return initResult.get(100, TimeUnit.MILLISECONDS);
       } catch (TimeoutException ex) {
           if (p != null && !p.isAlive()) {
               InitializeResult emptyResult = new InitializeResult();
               emptyResult.setCapabilities(new ServerCapabilities());
               return emptyResult;
           }
       }
   }
}
 
Example #4
Source File: InitHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testMissingResourceOperations() throws Exception {
	ClientCapabilities capabilities = new ClientCapabilities();
	WorkspaceClientCapabilities worspaceCapabilities = new WorkspaceClientCapabilities();
	worspaceCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
	capabilities.setWorkspace(worspaceCapabilities);
	ClientPreferences preferences = new ClientPreferences(capabilities);
	assertFalse(preferences.isResourceOperationSupported());
}
 
Example #5
Source File: ChangeConverter2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected ChangeConverter2(IResourceServiceProvider.Registry registry, WorkspaceEdit edit,
		ILanguageServerAccess access, UriExtensions uriExtensions) {
	this.registry = registry;
	this.uriExtensions = uriExtensions;
	this.edit = edit;
	this.access = access;
	Boolean documentChanges = null;
	if (access != null) {
		InitializeParams initializeParams = access.getInitializeParams();
		if (initializeParams != null) {
			ClientCapabilities clientCapabilities = initializeParams.getCapabilities();
			if (clientCapabilities != null) {
				WorkspaceClientCapabilities workspaceClientCapabilities = clientCapabilities.getWorkspace();
				if (workspaceClientCapabilities != null) {
					WorkspaceEditCapabilities workspaceEditCapabilities = workspaceClientCapabilities
							.getWorkspaceEdit();
					if (workspaceEditCapabilities != null) {
						documentChanges = workspaceEditCapabilities.getDocumentChanges();
					}
				}
			}
		}
	}
	this.useDocumentChanges = documentChanges == Boolean.TRUE;
	if (this.useDocumentChanges) {
		this.edit.setDocumentChanges(new ArrayList<>());
	} else {
		this.edit.setChanges(new LinkedHashMap<>());
	}
}
 
Example #6
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with MIT License 4 votes vote down vote up
@Override
    public InitializeParams getInitParams() {
        InitializeParams initParams = new InitializeParams();
        if (this.rootPath != null) {
            var root = rootPath.toURI().toString();
            if (this.useInputForWorkspace) {
                root = rootPath.toPath().relativize(inputFile.toPath()).toUri().toString();
            }

            initParams.setRootUri(root);
            LOGGER.info("Workspace root is {}", root);
        }
        WorkspaceClientCapabilities workspaceClientCapabilities = new WorkspaceClientCapabilities();
        workspaceClientCapabilities.setApplyEdit(true);
        workspaceClientCapabilities.setDidChangeWatchedFiles(new DidChangeWatchedFilesCapabilities());
        workspaceClientCapabilities.setExecuteCommand(new ExecuteCommandCapabilities());
        workspaceClientCapabilities.setWorkspaceEdit(new WorkspaceEditCapabilities());
//        workspaceClientCapabilities.setSymbol(new SymbolCapabilities());
        workspaceClientCapabilities.setWorkspaceFolders(true);
        workspaceClientCapabilities.setConfiguration(true);

        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setCodeAction(new CodeActionCapabilities());
        textDocumentClientCapabilities.setCompletion(new CompletionCapabilities(new CompletionItemCapabilities(false)));
        textDocumentClientCapabilities.setDefinition(new DefinitionCapabilities());
//        textDocumentClientCapabilities.setDocumentHighlight(new DocumentHighlightCapabilities());
        textDocumentClientCapabilities.setFormatting(new FormattingCapabilities());
//        textDocumentClientCapabilities.setHover(new HoverCapabilities());
//        textDocumentClientCapabilities.setOnTypeFormatting(new OnTypeFormattingCapabilities());
//        textDocumentClientCapabilities.setRangeFormatting(new RangeFormattingCapabilities());
        textDocumentClientCapabilities.setReferences(new ReferencesCapabilities());
        textDocumentClientCapabilities.setRename(new RenameCapabilities());
        textDocumentClientCapabilities.setSemanticHighlightingCapabilities(new SemanticHighlightingCapabilities(false));
        textDocumentClientCapabilities.setSignatureHelp(new SignatureHelpCapabilities());
        textDocumentClientCapabilities.setSynchronization(new SynchronizationCapabilities(true, true, true));
        initParams.setCapabilities(
                new ClientCapabilities(workspaceClientCapabilities, textDocumentClientCapabilities, null));
//        initParams.setInitializationOptions(null);
//        initParams.setInitializationOptions(
//                serverDefinition.getInitializationOptions(URI.create(initParams.getRootUri())));

        return initParams;
    }
 
Example #7
Source File: WorkspaceClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Capabilities specific to `WorkspaceEdit`s
 */
@Pure
public WorkspaceEditCapabilities getWorkspaceEdit() {
  return this.workspaceEdit;
}
 
Example #8
Source File: WorkspaceClientCapabilities.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Capabilities specific to `WorkspaceEdit`s
 */
public void setWorkspaceEdit(final WorkspaceEditCapabilities workspaceEdit) {
  this.workspaceEdit = workspaceEdit;
}