@Override
  protected List<? extends ICompletionProposal> computeProposals(
      final ITextViewer viewer, final int offset) {
    final IDocument document = viewer.getDocument();
    try {
      final String lineContent =
          DocumentUtilities.lineContentBeforeCurrentPosition(document, offset);
      final boolean shouldShowProposal = shouldShowProposals(lineContent, document, offset);

      if (shouldShowProposal) {
        final boolean isTsv = assist.isTsvFile();
        final Optional<IRegion> region =
            DocumentUtilities.findLiveCellRegion(document, isTsv, offset);
        final String prefix = DocumentUtilities.getPrefix(document, region, offset);
        final String content =
            region.isPresent()
                ? document.get(region.get().getOffset(), region.get().getLength())
                : "";
        final Image image =
            ImagesManager.getImage(RedImages.getImageForFileWithExtension(".robot"));

        final List<RedCompletionProposal> proposals = newArrayList();
        for (final IFile resourceFile : assist.getResourceFiles()) {

          final String resourcePath = resourceFile.getFullPath().makeRelative().toString();
          if (resourcePath.toLowerCase().startsWith(prefix.toLowerCase())) {
            final String resourceRelativePath =
                createCurrentFileRelativePath(resourceFile.getFullPath().makeRelative());
            final RedCompletionProposal proposal =
                RedCompletionBuilder.newProposal()
                    .will(assist.getAcceptanceMode())
                    .theText(resourceRelativePath)
                    .atOffset(offset - prefix.length())
                    .givenThatCurrentPrefixIs(prefix)
                    .andWholeContentIs(content)
                    .thenCursorWillStopAtTheEndOfInsertion()
                    .displayedLabelShouldBe(resourcePath)
                    .currentPrefixShouldBeDecorated()
                    .proposalsShouldHaveIcon(image)
                    .create();
            proposals.add(proposal);
          }
        }
        return proposals;
      }
      return null;
    } catch (final BadLocationException e) {
      return null;
    }
  }
 private boolean shouldShowProposals(
     final String lineContent, final IDocument document, final int offset)
     throws BadLocationException {
   return isInApplicableContentType(document, offset)
       && lineContent.toLowerCase().startsWith("resource")
       && DocumentUtilities.getNumberOfCellSeparators(lineContent, assist.isTsvFile()) == 1;
 }
示例#3
0
  @Override
  public void setRange(final IDocument document, final int offset, final int length) {
    this.document = (RobotDocument) document;

    if (lastTokenPosition == null
        || lastTokenPosition.getOffset() + lastTokenPosition.getLength() != offset) {
      this.tokensToAnalyze = null;
      this.analyzedTokens.clear();

      this.rangeOffset = offset;
      this.rangeLength = length;
      this.rangeLine = DocumentUtilities.getLine(document, offset);

      this.currentOffsetInToken = 0;
    }
  }