Search in sources :

Example 41 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class LanguageServerHarness method perform.

private void perform(WorkspaceEdit workspaceEdit) throws Exception {
    Assert.isNull("Versioned WorkspaceEdits not supported", workspaceEdit.getDocumentChanges());
    for (Entry<String, List<TextEdit>> entry : workspaceEdit.getChanges().entrySet()) {
        String uri = entry.getKey();
        TextDocumentInfo document = documents.get(uri);
        assertNotNull("Can't apply edits to non-existing document: " + uri, document);
        TextDocument workingDocument = new TextDocument(uri, document.getLanguageId());
        workingDocument.setText(document.getText());
        DocumentEdits edits = new DocumentEdits(workingDocument);
        for (TextEdit edit : entry.getValue()) {
            Range range = edit.getRange();
            edits.replace(document.toOffset(range.getStart()), document.toOffset(range.getEnd()), edit.getNewText());
        }
        edits.apply(workingDocument);
        Editor editor = getOpenEditor(uri);
        if (editor != null) {
            editor.setRawText(workingDocument.get());
        } else {
            changeDocument(uri, workingDocument.get());
        }
    }
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) DocumentEdits(org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits) TextEdit(org.eclipse.lsp4j.TextEdit) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CompletionList(org.eclipse.lsp4j.CompletionList) Range(org.eclipse.lsp4j.Range)

Example 42 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class MockYamlEditor method parseStructure.

public SRootNode parseStructure() throws Exception {
    YamlStructureProvider sp = YamlStructureProvider.DEFAULT;
    TextDocument _doc = new TextDocument(null, getLanguageId());
    _doc.setText(text);
    YamlDocument doc = new YamlDocument(_doc, sp);
    return sp.getStructure(doc);
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) YamlDocument(org.springframework.ide.vscode.commons.yaml.structure.YamlDocument) YamlStructureProvider(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureProvider)

Example 43 with TextDocument

use of org.springframework.ide.vscode.commons.util.text.TextDocument in project sts4 by spring-projects.

the class CommonLanguageTools method getValueType.

/**
 * Determine the value type for a give propertyName.
 */
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
    try {
        PropertyInfo prop = index.get(propertyName);
        if (prop != null) {
            return TypeParser.parse(prop.getType());
        } else {
            prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
            if (prop != null) {
                TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
                doc.setText(propertyName);
                PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
                return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) PropertyNavigator(org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigator) PropertyInfo(org.springframework.ide.vscode.boot.metadata.PropertyInfo)

Aggregations

TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)43 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)12 URI (java.net.URI)11 File (java.io.File)10 Location (org.eclipse.lsp4j.Location)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 ArrayList (java.util.ArrayList)7 SymbolInformation (org.eclipse.lsp4j.SymbolInformation)7 IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Range (org.eclipse.lsp4j.Range)6 Collection (java.util.Collection)5 Map (java.util.Map)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 Stream (java.util.stream.Stream)5 ASTParser (org.eclipse.jdt.core.dom.ASTParser)5 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)5