Exemplo n.º 1
0
  public void complete(
      ISourceModule module, int position, JstCompletion completion, List<CompletionProposal> list) {

    if (completion.inScope(ScopeIds.METHOD)) {
      handler.complete(module, position, completion, list);
    } else if (completion.inScope(ScopeIds.PROTOS) || completion.inScope(ScopeIds.PROPS)) {
      CompletionContext.setStaticContext(true);
      handler.complete(module, position, completion, list);
    }
  }
 private CompletionParameters createCompletionParameters(
     int invocationCount, final CompletionContext newContext, Editor editor) {
   final int offset = newContext.getStartOffset();
   final PsiFile fileCopy = newContext.file;
   PsiFile originalFile = fileCopy.getOriginalFile();
   final PsiElement insertedElement =
       findCompletionPositionLeaf(newContext, offset, fileCopy, originalFile);
   insertedElement.putUserData(CompletionContext.COMPLETION_CONTEXT_KEY, newContext);
   return new CompletionParameters(
       insertedElement, originalFile, myCompletionType, offset, invocationCount, editor);
 }
Exemplo n.º 3
0
  protected void doComplete(
      final int offset1,
      final int offset2,
      final CompletionContext context,
      final FileCopyPatcher dummyIdentifier,
      final Editor editor,
      final int invocationCount) {
    PsiFile file = context.file;
    int offset = context.getStartOffset();

    PsiElement lastElement = file.findElementAt(offset - 1);
    if (lastElement == null || !StringUtil.endsWithChar(lastElement.getText(), '@')) return;

    super.doComplete(offset1, offset2, context, dummyIdentifier, editor, invocationCount);
  }
  private void doComplete(
      CompletionInitializationContext initContext,
      boolean hasModifiers,
      int invocationCount,
      PsiFile hostCopy,
      OffsetMap hostMap,
      OffsetTranslator translator) {
    final Editor editor = initContext.getEditor();
    CompletionAssertions.checkEditorValid(editor);

    CompletionContext context =
        createCompletionContext(
            hostCopy,
            hostMap.getOffset(CompletionInitializationContext.START_OFFSET),
            hostMap,
            initContext.getFile());
    LookupImpl lookup = obtainLookup(editor);
    CompletionParameters parameters = createCompletionParameters(invocationCount, context, editor);

    CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
    if (phase instanceof CompletionPhase.CommittingDocuments) {
      if (phase.indicator != null) {
        phase.indicator.closeAndFinish(false);
      }
      ((CompletionPhase.CommittingDocuments) phase).replaced = true;
    } else {
      CompletionServiceImpl.assertPhase(CompletionPhase.NoCompletion.getClass());
    }

    final Semaphore freezeSemaphore = new Semaphore();
    freezeSemaphore.down();
    final CompletionProgressIndicator indicator =
        new CompletionProgressIndicator(
            editor,
            parameters,
            this,
            freezeSemaphore,
            initContext.getOffsetMap(),
            hasModifiers,
            lookup);
    Disposer.register(indicator, hostMap);
    Disposer.register(indicator, context.getOffsetMap());
    Disposer.register(indicator, translator);

    CompletionServiceImpl.setCompletionPhase(
        synchronous
            ? new CompletionPhase.Synchronous(indicator)
            : new CompletionPhase.BgCalculation(indicator));

    final AtomicReference<LookupElement[]> data = indicator.startCompletion(initContext);

    if (!synchronous) {
      return;
    }

    if (freezeSemaphore.waitFor(2000)) {
      final LookupElement[] allItems = data.get();
      if (allItems != null
          && !indicator.isRunning()
          && !indicator
              .isCanceled()) { // the completion is really finished, now we may auto-insert or show
        // lookup
        completionFinished(
            initContext.getStartOffset(),
            initContext.getSelectionEndOffset(),
            indicator,
            allItems,
            hasModifiers);
        checkNotSync(indicator, allItems);
        return;
      }
    }

    CompletionServiceImpl.setCompletionPhase(new CompletionPhase.BgCalculation(indicator));
    indicator.showLookup();
  }