Search in sources :

Example 1 with IRegion

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

the class ListLineTracker method getLineInformationOfOffset.

@Override
public final IRegion getLineInformationOfOffset(int position) throws BadLocationException {
    if (position > fTextLength)
        throw new BadLocationException();
    if (position == fTextLength) {
        int size = fLines.size();
        if (size == 0)
            return new Region(0, 0);
        Line l = fLines.get(size - 1);
        return (l.delimiter != null ? new Line(fTextLength, 0) : new Line(fTextLength - l.length, l.length));
    }
    return getLineInformation(findLine(position));
}
Also used : Region(org.springframework.ide.vscode.commons.util.text.Region) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion) BadLocationException(org.springframework.ide.vscode.commons.util.BadLocationException)

Example 2 with IRegion

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

the class YamlHoverInfoProvider method getHoverRegion.

private IRegion getHoverRegion(YamlFileAST ast, int offset) {
    if (ast != null) {
        Node n = ast.findNode(offset);
        if (n != null && n.getNodeId() == NodeId.scalar) {
            int start = n.getStartMark().getIndex();
            int end = n.getEndMark().getIndex();
            return new Region(start, end - start);
        }
    }
    return null;
}
Also used : Node(org.yaml.snakeyaml.nodes.Node) DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) Region(org.springframework.ide.vscode.commons.util.text.Region) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 3 with IRegion

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

the class IndentUtil method getReferenceIndent.

public String getReferenceIndent(int offset, IDocument doc) {
    // Apply indentfix, this is magic vscode seems to apply to edits returned by language server. So our harness has to
    // mimick that behavior. See https://github.com/Microsoft/language-server-protocol/issues/83
    IRegion referenceLine = doc.getLineInformationOfOffset(offset);
    DocumentRegion queryPrefix = new DocumentRegion(doc, referenceLine.getOffset(), offset);
    return queryPrefix.leadingWhitespace().toString();
}
Also used : DocumentRegion(org.springframework.ide.vscode.commons.util.text.DocumentRegion) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 4 with IRegion

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

the class VscodeHoverEngineAdapter method handle.

@Override
public Hover handle(TextDocumentPositionParams params) {
    // a trivial pre-resolved future.
    try {
        SimpleTextDocumentService documents = server.getTextDocumentService();
        TextDocument doc = documents.get(params);
        if (doc != null) {
            int offset = doc.toOffset(params.getPosition());
            Tuple2<Renderable, IRegion> hoverTuple = hoverInfoProvider.getHoverInfo(doc, offset);
            if (hoverTuple != null) {
                Renderable hoverInfo = hoverTuple.getT1();
                IRegion region = hoverTuple.getT2();
                Range range = doc.toRange(region.getOffset(), region.getLength());
                String rendered = render(hoverInfo, type);
                if (StringUtil.hasText(rendered)) {
                    Hover hover = new Hover(ImmutableList.of(Either.forLeft(rendered)), range);
                    return hover;
                }
            }
        }
    } catch (Exception e) {
        logger.error("error computing hover", e);
    }
    return SimpleTextDocumentService.NO_HOVER;
}
Also used : TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) Renderable(org.springframework.ide.vscode.commons.util.Renderable) Hover(org.eclipse.lsp4j.Hover) SimpleTextDocumentService(org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService) Range(org.eclipse.lsp4j.Range) IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Example 5 with IRegion

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

the class DocumentEdits method deleteLineBackward.

/**
 * Deletes the line of text with given line number, including either the following or
 * preceding newline. If there is a choice between the preceding or following newline,
 * the preceding newline is deleted. This will leave the cursor at the end of
 * the preceding line.
 * <p>
 * Note: a similar operation 'deleteLineForward' could be implemented prefering to
 * delete the following newline. This would be equivalent except that it will leave the
 * cursor at the start of the following line.
 */
public void deleteLineBackward(int lineNumber) throws BadLocationException {
    IRegion line = doc.getLineInformation(lineNumber);
    int startOfDeletion;
    int endOfDeletion;
    if (lineNumber > 0) {
        IRegion previousLine = doc.getLineInformation(lineNumber - 1);
        startOfDeletion = endOf(previousLine);
        endOfDeletion = endOf(line);
    } else if (lineNumber < doc.getNumberOfLines() - 1) {
        IRegion nextLine = doc.getLineInformation(lineNumber + 1);
        startOfDeletion = line.getOffset();
        endOfDeletion = nextLine.getOffset();
    } else {
        startOfDeletion = line.getOffset();
        endOfDeletion = endOf(line);
    }
    delete(startOfDeletion, endOfDeletion);
}
Also used : IRegion(org.springframework.ide.vscode.commons.util.text.IRegion)

Aggregations

IRegion (org.springframework.ide.vscode.commons.util.text.IRegion)10 DocumentRegion (org.springframework.ide.vscode.commons.util.text.DocumentRegion)4 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)3 Renderable (org.springframework.ide.vscode.commons.util.Renderable)3 Region (org.springframework.ide.vscode.commons.util.text.Region)2 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Hover (org.eclipse.lsp4j.Hover)1 Range (org.eclipse.lsp4j.Range)1 SPACES (org.springframework.ide.vscode.boot.common.CommonLanguageTools.SPACES)1 CommonLanguageTools.getValueHints (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueHints)1 CommonLanguageTools.getValueType (org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType)1 InformationTemplates (org.springframework.ide.vscode.boot.common.InformationTemplates)1 PropertyInfo (org.springframework.ide.vscode.boot.metadata.PropertyInfo)1 SpringPropertyIndex (org.springframework.ide.vscode.boot.metadata.SpringPropertyIndex)1 StsValueHint (org.springframework.ide.vscode.boot.metadata.hints.StsValueHint)1 Type (org.springframework.ide.vscode.boot.metadata.types.Type)1