vscode#CompletionContext TypeScript Examples

The following examples show how to use vscode#CompletionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: element-completion-item-povider.ts    From element-ui-helper with MIT License 6 votes vote down vote up
/**
   * 提供自动完成提示
   *
   * @param document 文档
   * @param position 位置
   * @param token token
   * @param context 上下文
   */
  provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
    this._document = document
    this._position = position
    this.token = token

    let tag: TagObject | undefined = this.getPreTag()
    let attr = this.getPreAttr()

    if (!tag || !/^[E|e]l/.test(tag.text || '')) {
      // 如果不是element的标签(E|el开头) 则返回 null 表示没有hover
      return null
    } else if (this.isAttrValueStart(tag, attr)) {
      // 如果是属性值的开始
      return this.getAttrValueCompletionItems(tag.text, attr)
    } else if (this.isEventStart(tag)) {
      // 优先判定事件
      return this.getEventCompletionItems(tag.text)
    } else if (this.isAttrStart(tag)) {
      // 判断属性
      return this.getAttrCompletionItems(tag.text)
    } else if (this.isTagStart()) {
      // 判断标签
      return this.getTagCompletionItems(tag.text)
    }

    return null
  }
Example #2
Source File: macroAutocompletionProvider.ts    From vscode-dbt-power-user with MIT License 6 votes vote down vote up
provideCompletionItems(
    document: TextDocument,
    position: Position,
    token: CancellationToken,
    context: CompletionContext
  ): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
    const range = document.getWordRangeAtPosition(position);
    if (range && isEnclosedWithinCodeBlock(document, range)) {
      return this.getAutoCompleteItems(document.uri);
    }
    return undefined;
  }
Example #3
Source File: modelAutocompletionProvider.ts    From vscode-dbt-power-user with MIT License 6 votes vote down vote up
provideCompletionItems(
    document: TextDocument,
    position: Position,
    token: CancellationToken,
    context: CompletionContext
  ): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
    const linePrefix = document
      .lineAt(position)
      .text.substr(0, position.character);
    if (
      linePrefix.match(ModelAutocompletionProvider.ENDS_WITH_REF) &&
      isEnclosedWithinCodeBlock(document, position)
    ) {
      return this.getAutoCompleteItems(document.uri);
    }

    return undefined;
  }
Example #4
Source File: sourceAutocompletionProvider.ts    From vscode-dbt-power-user with MIT License 6 votes vote down vote up
provideCompletionItems(
    document: TextDocument,
    position: Position,
    token: CancellationToken,
    context: CompletionContext
  ): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
    const linePrefix = document
      .lineAt(position)
      .text.substr(0, position.character);
    if (!isEnclosedWithinCodeBlock(document, position)) {
      return undefined;
    }
    const projectRootpath = this.dbtProjectContainer.getProjectRootpath(
      document.uri
    );
    if (projectRootpath === undefined) {
      return;
    }

    if (linePrefix.match(SourceAutocompletionProvider.ENDS_WITH_SOURCE)) {
      return this.showSourceNameAutocompletionItems(projectRootpath);
    }

    if (
      linePrefix.match(SourceAutocompletionProvider.GET_SOURCE_NAME) &&
      linePrefix.includes("source")
    ) {
      return this.showTableNameAutocompletionItems(linePrefix, projectRootpath);
    }
    return undefined;
  }
Example #5
Source File: ALDocCommentProvider.ts    From vscode-alxmldocumentation with MIT License 5 votes vote down vote up
/**
     * Provide XML Documentation Completion Items (IntelliSense) based on triggering position.
     * @param document Actual Document.
     * @param position Trigger Position.
     * @param token CancellationToken.
     * @param context CompletionContext.
     */
    async provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): Promise<CompletionItem[] | CompletionList<CompletionItem> | null | undefined> {        
        this.alXmlDocCompletionItems = [];

        if (!Configuration.IntelliSenseDocumentationIsEnabled(document.uri)) {
            return;
        }
        
        if (context.triggerCharacter === undefined) {
            return;
        }
        
        let activeLine = ALSyntaxUtil.SplitALCodeToLines(document.getText())[position.line];
        if (activeLine.match(/^[ \t]*\/{3}[ \t]*$/) === null) {
            return;
        }        

        let alObject: ALObject | null = await ALSyntaxUtil.GetALObject(document);
        if (alObject === null) {
            return;
        }

        if (alObject.LineNo > position.line) {     
            this.ProvideALObjectCompletionItems(alObject);
        } else {
            // find procedure
            let alProcedure: ALProcedure | undefined = alObject.Procedures?.find(alProcedure => (alProcedure.LineNo > position.line));
            if (!alProcedure) {
                return;
            }
            
            await this.ProvideALProcedureCompletionItems(alObject, alProcedure);
        }

        return this.alXmlDocCompletionItems;
    }
Example #6
Source File: microProfileCompletionItemProvider.ts    From vscode-microprofile with Apache License 2.0 5 votes vote down vote up
provideCompletionItems(
      document: TextDocument,
      position: Position,
      _token: CancellationToken,
      _context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
    return commands.executeCommand("java.execute.workspaceCommand", JAVA_COMPLETION_REQUEST, adaptToMicroProfileCompletionParams(document, position));
  }
Example #7
Source File: NextObjectIdCompletionProvider.ts    From al-objid with MIT License 5 votes vote down vote up
async provideCompletionItems(
        document: TextDocument,
        position: Position,
        token: CancellationToken,
        context: CompletionContext
    ) {
        const nextIdContext: NextIdContext = { injectSemicolon: false };
        const type = await getTypeAtPosition(document, position, nextIdContext);
        if (!type) {
            return;
        }

        const app = WorkspaceManager.instance.getALAppFromUri(document.uri);
        if (!app) {
            return;
        }

        const objectId = await Backend.getNextNo(app, type, app.manifest.idRanges, false);
        Telemetry.instance.log("getNextNo-fetch", app.hash);

        if (showNotificationsIfNecessary(app, objectId) || !objectId) return [];
        output.log(`Suggesting object ID auto-complete for ${type} ${objectId.id}`);

        if (Array.isArray(objectId.id)) {
            if (!objectId.id.length) {
                objectId.id.push(0);
            }

            const items: NextObjectIdCompletionItem[] = [];
            const logicalNames: string[] = [];
            for (let i = 0; i < objectId.id.length; i++) {
                const id = objectId.id[i];
                const range = getRangeForId(id as number, app.config.getObjectTypeRanges(type));
                if (range && range.description) {
                    if (logicalNames.includes(range.description)) {
                        continue;
                    }
                    logicalNames.push(range.description);
                }
                const objectIdCopy = { ...objectId, id };
                const deeperContext = {
                    ...nextIdContext,
                    requireId: id,
                    additional: { ordinal: i },
                } as NextIdContext;
                items.push(
                    new NextObjectIdCompletionItem(
                        type,
                        objectIdCopy,
                        app,
                        position,
                        document.uri,
                        deeperContext,
                        range
                    )
                );
            }
            return items;
        } else {
            return [new NextObjectIdCompletionItem(type, objectId, app, position, document.uri, nextIdContext)];
        }
    }