vscode#CodeLens TypeScript Examples

The following examples show how to use vscode#CodeLens. 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: codelens-provider.ts    From plugin-vscode with Apache License 2.0 6 votes vote down vote up
private async getCodeLensList() {
        let codeLenses: CodeLens[] = [];
        await this.ballerinaExtension.langClient!.getExecutorPositions({
            documentIdentifier: {
                uri: window.activeTextEditor!.document.uri.toString()
            }
        }).then(response => {
            if (response.executorPositions) {
                response.executorPositions.forEach(position => {
                    codeLenses.push(this.createCodeLens(position, EXEC_TYPE.RUN));
                    codeLenses.push(this.createCodeLens(position, EXEC_TYPE.DEBUG));
                });
            }
        });
        return codeLenses;
    }
Example #2
Source File: codelens-provider.ts    From plugin-vscode with Apache License 2.0 6 votes vote down vote up
private createCodeLens(execPosition: ExecutorPosition, execType: EXEC_TYPE): CodeLens {
        const startLine = execPosition.range.startLine.line;
        const startColumn = execPosition.range.startLine.offset;
        const endLine = execPosition.range.endLine.line;
        const endColumn = execPosition.range.endLine.offset;
        const codeLens = new CodeLens(new Range(startLine, startColumn, endLine, endColumn));
        codeLens.command = {
            title: execType.toString(),
            tooltip: `${execType.toString()} ${execPosition.name}`,
            command: execPosition.kind === EXEC_POSITION_TYPE.SOURCE ? (execType === EXEC_TYPE.RUN ? PALETTE_COMMANDS.RUN :
                SOURCE_DEBUG_COMMAND) : (execType === EXEC_TYPE.RUN ? PALETTE_COMMANDS.TEST : TEST_DEBUG_COMMAND),
            arguments: execPosition.kind === EXEC_POSITION_TYPE.SOURCE ? [] : (execType === EXEC_TYPE.RUN ?
                [EXEC_ARG.TESTS, execPosition.name] : [execPosition.name])
        };
        return codeLens;
    }
Example #3
Source File: comment-lens-provider.ts    From vscode-code-review with MIT License 6 votes vote down vote up
public provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]> {
    return this.exportFactory.getFilesContainingComments().then((filesWithComments) => {
      const codeLenses: CodeLens[] = [];
      filesWithComments.forEach((el) => {
        if (document.fileName.endsWith(el.data.group)) {
          el.data.lines.forEach((csvEntry) => {
            const fileSection: ReviewFileExportSection = {
              group: csvEntry.filename,
              lines: el.data.lines,
            };
            const csvRef: CsvEntry | undefined = csvEntry;
            const prio = Number(csvEntry.priority); // be sure the value is a number
            const priorityString = prio
              ? ` | Priority: ${csvEntry.priority}${symbolForPriority(Number(csvEntry.priority))}`
              : '';
            const command: Command = {
              title: `Code Review: ${csvEntry.title}${priorityString}`,
              tooltip: csvEntry.comment,
              command: 'codeReview.openSelection',
              arguments: [fileSection, csvRef],
            };

            rangesFromStringDefinition(csvEntry.lines).forEach((range: Range) => {
              codeLenses.push(new CodeLens(range, command));
            });
          });
        }
      });
      return codeLenses;
    });
  }
Example #4
Source File: codelens-provider.ts    From plugin-vscode with Apache License 2.0 5 votes vote down vote up
provideCodeLenses(_document: TextDocument, _token: CancellationToken): ProviderResult<CodeLens[]> {
        let codeLenses: CodeLens[] = [];
        if (this.ballerinaExtension.langClient && window.activeTextEditor) {
            return this.getCodeLensList();
        }
        return codeLenses;
    }