Java 类org.eclipse.jface.text.provisional.codelens.ICodeLens 实例源码

项目:codelens-eclipse    文件:ClassReferencesCodeLensProvider.java   
@Override
public ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    IDocument document = textViewer.getDocument();
    List<ICodeLens> lenses = new ArrayList<>();
    int lineCount = document.getNumberOfLines();
    for (int i = 0; i < lineCount; i++) {
        String line = getLineText(document, i, false);
        int index = line.indexOf("class ");
        if (index != -1) {
            String className = line.substring(index + "class ".length(), line.length());
            index = className.indexOf(" ");
            if (index != -1) {
                className = className.substring(0, index);
            }
            if (className.length() > 0) {
                lenses.add(new ClassCodeLens(className, i + 1));
            }
        }
    }
    return lenses.toArray(new ICodeLens[0]);
}
项目:codelens-eclipse    文件:LSPCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens codeLens,
        IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();

    LSPDocumentInfo info = null;
    Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(
            LSPEclipseUtils.getDocument((ITextEditor) textEditor),
            capabilities -> capabilities.getCodeLensProvider() != null
                    && capabilities.getCodeLensProvider().isResolveProvider());
    if (!infos.isEmpty()) {
        info = infos.iterator().next();
    } else {
        info = null;
    }
    if (info != null) {
        LSPCodeLens lscl = ((LSPCodeLens) codeLens);
        CodeLens unresolved = lscl.getCl();
        return info.getLanguageClient().getTextDocumentService().resolveCodeLens(unresolved).thenApply(resolved -> {
            lscl.update(resolved);
            return lscl;
        });
    }
    return null;
}
项目:ec4e    文件:EditorConfigCodeLensProvider.java   
@Override
protected ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
    IFile file = EditorUtils.getFile(textEditor);
    if (file == null) {
        return null;
    }
    EditorConfigCodeLens cl = (EditorConfigCodeLens) codeLens;
    CountSectionPatternVisitor visitor = new CountSectionPatternVisitor(cl.getSection());
    try {
        file.getParent().accept(visitor, IResource.NONE);
        cl.update(visitor.getNbFiles() + " files match");
    } catch (CoreException e) {
        cl.update(e.getMessage());
    }
    return cl;
}
项目:codelens-eclipse    文件:CodeLensViewZone.java   
public String getText(GC gc, int x) {
    hoveredCodeLens = null;
    hoveredCodeLensStartX = null;
    hoveredCodeLensEndX = null;
    if (resolvedSymbols == null || resolvedSymbols.size() < 1) {
        return "no command";
    } else {
        StringBuilder text = new StringBuilder();
        int i = 0;
        boolean hasHover = hover != null;
        for (ICodeLens codeLens : resolvedSymbols) {
            if (i > 0) {
                text.append(" | ");
            }
            Integer startX = null;
            if (hasHover && hoveredCodeLens == null) {
                startX = gc.textExtent(text.toString()).x + x;
            }
            text.append(codeLens.getCommand().getTitle());
            if (hasHover && hoveredCodeLens == null) {
                int endX = gc.textExtent(text.toString()).x + x;
                if (hover.x < endX) {
                    hoveredCodeLensStartX = startX;
                    hoveredCodeLensEndX = endX;
                    hoveredCodeLens = codeLens;
                }
            }
            i++;
        }
        return text.toString();
    }
}
项目:codelens-eclipse    文件:JavaCodeLensProvider.java   
private void collectCodeLenses(ITypeRoot unit, IJavaElement[] elements, List<ICodeLens> lenses,
        IProgressMonitor monitor) throws JavaModelException {
    for (IJavaElement element : elements) {
        if (monitor.isCanceled()) {
            return;
        }
        if (element.getElementType() == IJavaElement.TYPE) {
            collectCodeLenses(unit, ((IType) element).getChildren(), lenses, monitor);
        } else if (element.getElementType() != IJavaElement.METHOD || JDTUtils.isHiddenGeneratedElement(element)) {
            continue;
        }

        // if (preferenceManager.getPreferences().isReferencesCodeLensEnabled()) {
        ICodeLens lens = getCodeLens(REFERENCES_TYPE, element, unit);
        lenses.add(lens);
        // }
        // if (preferenceManager.getPreferences().isImplementationsCodeLensEnabled() &&
        // element instanceof IType) {
        if (element instanceof IType) {
            IType type = (IType) element;
            if (type.isInterface() || Flags.isAbstract(type.getFlags())) {
                lens = getCodeLens(IMPLEMENTATION_TYPE, element, unit);
                lenses.add(lens);
            }
        }
    }
}
项目:codelens-eclipse    文件:JavaCodeLensProvider.java   
private ICodeLens getCodeLens(String type, IJavaElement element, ITypeRoot unit) throws JavaModelException {
    ISourceRange r = ((ISourceReference) element).getNameRange();
    final Range range = JDTUtils.toRange(unit, r.getOffset(), r.getLength());

    ICodeLens lens = new JavaCodeLens(range, type);

    // String uri = ResourceUtils.toClientUri(JDTUtils.getFileURI(unit));
    // lens.setData(Arrays.asList(uri, range.getStart(), type));
    return lens;
}
项目:codelens-eclipse    文件:ClassReferencesCodeLensProvider.java   
@Override
public ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    IDocument document = textViewer.getDocument();
    String className = ((ClassCodeLens) codeLens).getClassName();
    int refCount = 0;
    int lineCount = document.getNumberOfLines();
    for (int i = 0; i < lineCount; i++) {
        String line = getLineText(document, i, false);
        refCount += line.contains("new " + className) ? 1 : 0;
    }
    ((ClassCodeLens) codeLens).setCommand(new Command(refCount + " references", ""));
    return codeLens;
}
项目:codelens-eclipse    文件:ClassImplementationsCodeLensProvider.java   
@Override
public ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    IDocument document = textViewer.getDocument();
    List<ICodeLens> lenses = new ArrayList<>();
    int lineCount = document.getNumberOfLines();
    for (int i = 0; i < lineCount; i++) {
        updateCodeLens(i, document, "class ", lenses);
        updateCodeLens(i, document, "interface ", lenses);
    }
    return lenses.toArray(new ICodeLens[0]);
}
项目:codelens-eclipse    文件:ClassImplementationsCodeLensProvider.java   
private void updateCodeLens(int lineIndex, IDocument document, String token, List<ICodeLens> lenses) {
    String line = getLineText(document, lineIndex, false);
    int index = line.indexOf(token);
    if (index != -1) {
        String className = line.substring(index + token.length(), line.length());
        index = className.indexOf(" ");
        if (index != -1) {
            className = className.substring(0, index);
        }
        if (className.length() > 0) {
            lenses.add(new ClassCodeLens(className, lineIndex + 1));
        }
    }
}
项目:codelens-eclipse    文件:ClassImplementationsCodeLensProvider.java   
@Override
public ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    IDocument document = textViewer.getDocument();
    String className = ((ClassCodeLens) codeLens).getClassName();
    int refCount = 0;
    int lineCount = document.getNumberOfLines();
    for (int i = 0; i < lineCount; i++) {
        String line = getLineText(document, i, false);
        refCount += line.contains("implements " + className) ? 1 : 0;
    }
    ((ClassCodeLens) codeLens).setCommand(new Command(refCount + " implementation", ""));
    return codeLens;
}
项目:ec4e    文件:EditorConfigCodeLensProvider.java   
@Override
protected ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
    IFile file = EditorUtils.getFile(textEditor);
    if (file == null) {
        return null;
    }
    IDocument document = context.getViewer().getDocument();
    IDEEditorConfigManager editorConfigManager = IDEEditorConfigManager.getInstance();
    final ErrorHandler errorHandler = ErrorHandler.IGNORING;
    SectionsHandler handler = new SectionsHandler(editorConfigManager.getRegistry(), editorConfigManager.getVersion());
    EditorConfigParser parser = EditorConfigParser.default_();
    try {
        parser.parse(Resources.ofString(file.getFullPath().toString(), document.get()), handler, errorHandler );
    } catch (IOException e) {
        /* Will not happen with Resources.ofString() */
        throw new RuntimeException(e);
    }
    List<Section> sections = handler.getEditorConfig().getSections();
    List<Location> sectionLocations = handler.getSectionLocations();

    ICodeLens[] lenses = new ICodeLens[sections.size()];
    for (int i = 0; i < lenses.length; i++) {
        lenses[i] = new EditorConfigCodeLens(sections.get(i), sectionLocations.get(i), file);
    }
    return lenses;
}
项目:typescript.java    文件:TypeScriptBaseCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens[]> provideCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    IResource resource = TypeScriptResourceUtil.getFile(textViewer.getDocument());
    if (resource == null) {
        return null;
    }
    if (TypeScriptResourceUtil.canConsumeTsserver(resource)) {
        // the project of the resource has typescript nature, execute
        // typescript
        // navtree.
        try {
            IProject project = resource.getProject();
            IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(project);
            IDocument document = textViewer.getDocument();
            IIDETypeScriptFile tsFile = tsProject.openFile(resource, document);
            return tsProject.getClient().navtree(tsFile.getName(), tsFile).thenApply(tree -> {
                List<Range> referenceableSpans = new ArrayList<>();
                if (tree != null && tree.hasChildItems()) {
                    tree.getChildItems().forEach(item -> this.walkNavTree(tsFile, item, null, referenceableSpans));
                }
                return toCodeLenses(referenceableSpans, tsFile);
            });
        } catch (Exception e) {
            TypeScriptUIPlugin.log("Error while TypeScript codelens", e);
        }
    }
    return null;
}
项目:typescript.java    文件:TypeScriptImplementationsCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgressMonitor monitor) {
    ImplementationsCodeLens codeLens = (ImplementationsCodeLens) cl;
    // const codeLens = inputCodeLens as ReferencesCodeLens;
    // const args: Proto.FileLocationRequestArgs = {
    // file: codeLens.file,
    // line: codeLens.range.start.line + 1,
    // offset: codeLens.range.start.character + 1
    // };
    IIDETypeScriptFile tsFile = codeLens.getTsFile();
    try {
        int position = tsFile.getPosition(codeLens.getRange().startLineNumber, codeLens.getRange().startColumn);
        return tsFile.implementation(position).thenApply(refs -> {
            int refCount = refs.size();
            if (refCount == 1) {
                codeLens.setCommand(new Command("1 implementation", "implementation"));
            } else {
                codeLens.setCommand(
                        new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
            }
            return codeLens;
        });
    } catch (Exception e) {
        codeLens.setCommand(new Command("Could not determine implementations", null));
    }
    return null;
}
项目:codelens-eclipse    文件:CodeLensViewZone.java   
public void updateCommands(List<ICodeLens> resolvedSymbols) {
    this.resolvedSymbols = resolvedSymbols;
}
项目:codelens-eclipse    文件:CodeLens.java   
public void updateCommands(List<ICodeLens> resolvedSymbols) {
    zone.updateCommands(resolvedSymbols);
}
项目:codelens-eclipse    文件:CodeLensData.java   
public CodeLensData(ICodeLens symbol, ICodeLensProvider provider) {
    this.symbol = symbol;
    this.provider = provider;
}
项目:codelens-eclipse    文件:CodeLensData.java   
public ICodeLens getSymbol() {
    return symbol;
}
项目:codelens-eclipse    文件:LSPCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens[]> provideCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();

    LSPDocumentInfo info = null;
    Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(
            LSPEclipseUtils.getDocument((ITextEditor) textEditor),
            capabilities -> capabilities.getCodeLensProvider() != null);
    if (!infos.isEmpty()) {
        info = infos.iterator().next();
    } else {
        info = null;
    }
    if (info != null) {

        CodeLensParams param = new CodeLensParams(new TextDocumentIdentifier(info.getFileUri().toString()));
        final CompletableFuture<List<? extends CodeLens>> codeLens = info.getLanguageClient()
                .getTextDocumentService().codeLens(param);
        return codeLens.thenApply(lens -> {
            List<ICodeLens> lenses = new ArrayList<>();
            for (CodeLens cl : lens) {
                lenses.add(new LSPCodeLens(cl));
            }
            return lenses.toArray(new ICodeLens[lenses.size()]);
        });
        // try {
        //
        //
        //
        // List<ICodeLens> lenses = new ArrayList<>();
        // List<? extends CodeLens> lens = codeLens.get(5000, TimeUnit.MILLISECONDS);
        // for (CodeLens cl : lens) {
        // lenses.add(new LSPCodeLens(cl));
        // }
        // return lenses.toArray(new ICodeLens[lenses.size()]);
        // } catch (Exception e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
        // }

    }
    return null;
}
项目:typescript.java    文件:TypeScriptReferencesCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens cl,
        IProgressMonitor monitor) {
    ReferencesCodeLens codeLens = (ReferencesCodeLens) cl;
    // const codeLens = inputCodeLens as ReferencesCodeLens;
    // const args: Proto.FileLocationRequestArgs = {
    // file: codeLens.file,
    // line: codeLens.range.start.line + 1,
    // offset: codeLens.range.start.character + 1
    // };
    IIDETypeScriptFile tsFile = codeLens.getTsFile();
    try {
        int position = tsFile.getPosition(codeLens.getRange().startLineNumber, codeLens.getRange().startColumn);
        return tsFile.references(position).thenApply(body -> {
            int refCount = body.getRefs().size() - 1;
            if (refCount == 1) {
                codeLens.setCommand(new Command("1 reference", "references"));
            } else {
                codeLens.setCommand(new Command(MessageFormat.format("{0} references", refCount), "references"));
            }
            return codeLens;
        });
    } catch (Exception e) {
        codeLens.setCommand(new Command("Could not determine references", null));
    }
    return null;
    // return this.client.execute('references', args, token).then(response
    // => {
    // if (!response || !response.body) {
    // throw codeLens;
    // }
    //
    // const locations = response.body.refs
    // .map(reference =>
    // new Location(this.client.asUrl(reference.file),
    // new Range(
    // reference.start.line - 1, reference.start.offset - 1,
    // reference.end.line - 1, reference.end.offset - 1)))
    // .filter(location =>
    // // Exclude original definition from references
    // !(location.uri.fsPath === codeLens.document.fsPath &&
    // location.range.start.isEqual(codeLens.range.start)));
    //
    // codeLens.command = {
    // title: locations.length === 1
    // ? localize('oneReferenceLabel', '1 reference')
    // : localize('manyReferenceLabel', '{0} references', locations.length),
    // command: locations.length ? 'editor.action.showReferences' : '',
    // arguments: [codeLens.document, codeLens.range.start, locations]
    // };
    // return codeLens;
    // }).catch(() => {
    // codeLens.command = {
    // title: localize('referenceErrorLabel', 'Could not determine
    // references'),
    // command: ''
    // };
    // return codeLens;
    // });
}
项目:typescript.java    文件:TypeScriptReferencesCodeLensProvider.java   
@Override
protected ICodeLens[] toCodeLenses(List<Range> referenceableSpans, IIDETypeScriptFile tsFile) {
    return referenceableSpans.stream().map(span -> new ReferencesCodeLens(tsFile, span))
            .collect(Collectors.toList()).toArray(new ICodeLens[0]);
}
项目:typescript.java    文件:TypeScriptImplementationsCodeLensProvider.java   
@Override
protected ICodeLens[] toCodeLenses(List<Range> referenceableSpans, IIDETypeScriptFile tsFile) {
    return referenceableSpans.stream().map(span -> new ImplementationsCodeLens(tsFile, span))
            .collect(Collectors.toList()).toArray(new ICodeLens[0]);
}
项目:typescript.java    文件:TypeScriptBaseCodeLensProvider.java   
protected abstract ICodeLens[] toCodeLenses(List<Range> referenceableSpans, IIDETypeScriptFile tsFile);