当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vscode.Range类代码示例

本文整理汇总了TypeScript中vscode.Range的典型用法代码示例。如果您正苦于以下问题:TypeScript Range类的具体用法?TypeScript Range怎么用?TypeScript Range使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Range类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: exec

        const nak = exec(cmd, (err, stdout, stderr) => {
            if (err || stderr) {
                return reject(err || stderr);
            }

            let result: vscode.Location[] = [];
            let lines = stdout.split('\n');
            let lastUri: vscode.Uri;
            let lastMatch: RegExpMatchArray;

            for (let line of lines) {
                if (line[0] === ':') {
                    lastUri = vscode.Uri.file(line.substr(1));
                } else if (lastMatch = /^(\d+);\d+ (\d+)/.exec(line)) {
                    let line = parseInt(lastMatch[1]) - 1;
                    let end = parseInt(lastMatch[2]);
                    range = new vscode.Range(line, end - word.length + 1, line, end);

                    if (lastUri.toString() !== document.uri.toString() || !range.contains(pos)) {
                        result.push(new vscode.Location(lastUri, range));
                    }
                }
            }

            resolve(result);
        });
开发者ID:jrieken,项目名称:fuzzy-definitions,代码行数:26,代码来源:search.ts

示例2: updateDecorations

function updateDecorations(editor, decoration, line?) {
    if (!editor) {
      return;
    }

    const regEx = /^[\t\s]+$/gm;
    var text = editor.document.getText();
    var tabsize = editor.options.tabSize
    var tabs = " ".repeat(tabsize)
    var decor: vscode.DecorationOptions[] = [];
    var match;

    const currentLine = editor.selection.active;
    const currentLineRange = new vscode.Range(new vscode.Position(currentLine.line, 0), currentLine);

    while (match = regEx.exec(text)) {
      var startPos = editor.document.positionAt(match.index);
      var endPos = editor.document.positionAt(match.index + match[0].length);
      let range = new vscode.Range(startPos, endPos);
      if (editor.selection.isEmpty && range.contains(currentLineRange)) {
        const rangeBeforeSelection = new vscode.Range(range.start, currentLineRange.start);
        const rangeAfterSelection = new vscode.Range(currentLineRange.end, range.end);

        var decorationPosBefore = { range: rangeBeforeSelection, hoverMessage: null };
        var decorationPosAfter = { range: rangeAfterSelection, hoverMessage: null };
        decor.push(decorationPosBefore);
        decor.push(decorationPosAfter);
      } else {
        var decorationPos = { range: range, hoverMessage: null };
        decor.push(decorationPos);
      }
    }

    editor.setDecorations(decoration, decor);
}
开发者ID:DmitryDorofeev,项目名称:vscode-empty-indent,代码行数:35,代码来源:extension.ts

示例3: Range

		cachedScriptsMap!.forEach((value, key) => {
			let start = document.positionAt(value[0]);
			let end = document.positionAt(value[0] + value[1]);
			let range = new Range(start, end);

			if (range.contains(position)) {
				let contents: MarkdownString = new MarkdownString();
				contents.isTrusted = true;
				contents.appendMarkdown(this.createRunScriptMarkdown(key, document.uri));

				let debugArgs = extractDebugArgFromScript(value[2]);
				if (debugArgs) {
					contents.appendMarkdown(this.createDebugScriptMarkdown(key, document.uri, debugArgs[0], debugArgs[1]));
				}
				hover = new Hover(contents);
			}
		});
开发者ID:developers23,项目名称:vscode,代码行数:17,代码来源:scriptHover.ts

示例4: getArgumentIndex

    /**
     * Finds the index of the argument at a given position.
     * @param pos The position to get the argument index from.
     * @param defaultTo Default value to return if an argument was not found.
     * Returns the argument index or defaultTo value.
     */
    public getArgumentIndex(pos: Position, defaultTo: number = -1)
    {
        let arg: ILuaParseCallExpressionArgument;

        for(let i = 0; i < this.arguments.length; i++)
        {
            arg = this.arguments[i];

            let range = new Range(
                new Position(arg.loc.start.line - 1, arg.loc.start.column - 1),
                new Position(arg.loc.end.line - 1, arg.loc.end.column)
            )

            if (range.contains(pos))
            {
                return i;
            }
        }

        return defaultTo;
    }
开发者ID:Janne252,项目名称:vscode-scar,代码行数:27,代码来源:callExpression.ts

示例5: Range

        return activeTextEditor.edit((editBuilder) => {
            const rangeByLine = (line: number): Range => {
                if (line >= activeTextEditor.document.lineCount - 1) {
                    return;
                }

                const thisLine = activeTextEditor.document.lineAt(line).text;
                const nextLine = activeTextEditor.document.lineAt(line + 1).text;

                const thisLineTrimLength = (() => {
                    const matches = thisLine.match(/\s+$/);
                    return matches ? matches[0].length : 0;
                })();
                const nextLineTrimLength = (() => {
                    const matches = nextLine.match(/^\s+/);
                    return matches ? matches[0].length : 0;
                })();

                return new Range(
                    line, thisLine.length - thisLineTrimLength,
                    line + 1, nextLineTrimLength
                );
            };

            let linesToJoin: number[] = [];
            activeTextEditor.selections.forEach(selection => {
                if (selection.isSingleLine) {
                    linesToJoin.push(selection.active.line);
                }
                else {
                    for (let line = selection.start.line; line < selection.end.line; line++) {
                        linesToJoin.push(line);
                    }
                }
            });

            let ranges: Range[] = [];
            linesToJoin.forEach(line => {
                const range = rangeByLine(line);
                if (range) {
                    ranges.push(range);
                }
            });

            ranges = UtilRange.unionOverlaps(ranges);

            ranges.forEach(range => {
                editBuilder.replace(range, ' ');
            });
        })
开发者ID:Beatusvir,项目名称:amVim-for-VSCode,代码行数:50,代码来源:JoinLines.ts

示例6: intersectDiffWithRange

export function intersectDiffWithRange(textDocument: TextDocument, diff: LineChange, range: Range): LineChange | null {
	const modifiedRange = getModifiedRange(textDocument, diff);
	const intersection = range.intersection(modifiedRange);

	if (!intersection) {
		return null;
	}

	if (diff.modifiedEndLineNumber === 0) {
		return diff;
	} else {
		return {
			originalStartLineNumber: diff.originalStartLineNumber,
			originalEndLineNumber: diff.originalEndLineNumber,
			modifiedStartLineNumber: intersection.start.line + 1,
			modifiedEndLineNumber: intersection.end.line + 1
		};
	}
}
开发者ID:Chan-PH,项目名称:vscode,代码行数:19,代码来源:staging.ts

示例7: getType

async function getType(
    session: Session,
    sel: vscode.Selection | vscode.Position | vscode.Range,
    doc: vscode.TextDocument):
    Promise<null | [vscode.Range, string]> {

    const selRangeOrPos: vscode.Range | vscode.Position = (() => {
        if (sel instanceof vscode.Selection) {
            return new vscode.Range(sel.start, sel.end);
        } else {
            return sel;
        }
    })();

    if (session.loading === null) {
        session.reload();
    }

    await session.loading;

    const typesB: string[] =
        session.typeCache !== null
        ? session.typeCache
        : await session.ghci.sendCommand(':all-types');

    session.typeCache = typesB;

    const strTypes = typesB.filter((x) => x.startsWith(doc.uri.fsPath));

    const allTypes = strTypes.map((x) =>
        /^:\((\d+),(\d+)\)-\((\d+),(\d+)\): (.*)$/.exec(x.substr(doc.uri.fsPath.length)));

    let curBestRange: null | vscode.Range = null, curType: null | string = null;

    for (const [_whatever, startLine, startCol, endLine, endCol, type] of allTypes) {
        const curRange = new vscode.Range(+startLine - 1, +startCol - 1, +endLine - 1, +endCol - 1);
        if (curRange.contains(selRangeOrPos)) {
            if (curBestRange === null || curBestRange.contains(curRange)) {
                curBestRange = curRange;
                curType = type;
            }
        }
    }

    if (curType === null) {
        return null;
    } else {
        // :all-types gives types with implicit forall type variables,
        // but :kind! doesn't like them, so we try to patch this fact

        const re = /[A-Za-z0-9_']*/g
        const typeVariables = curType.match(re).filter((u) =>
            u.length && u !== 'forall' && /[a-z]/.test(u[0]));
        const forallPart = `forall ${[...new Set(typeVariables)].join(' ')}.`
        const fullType = `${forallPart} ${curType}`;
        
        const res = await session.ghci.sendCommand([
            ':seti -XExplicitForAll -XKindSignatures',
            `:kind! ((${fullType}) :: *)`]);

        const resolved: null | string = (() => {
            // GHCi may output warning messages before the response
            while (res.length && res[0] !== `((${fullType}) :: *) :: *`) res.shift();

            if (res.length && res[1].startsWith('= ')) {
                res.shift();
                res[0] = res[0].slice(1); // Skip '=' on second line
                return res.join(' ').replace(/\s{2,}/g, ' ').trim();
            } else {
                return null;
            }
        })();

        if (resolved) {
            return [curBestRange, resolved];
        } else {
            return [curBestRange, curType.replace(/([A-Z][A-Za-z0-9_']*\.)+([A-Za-z0-9_']+)/g, '$2')];
        }
    }
}
开发者ID:OlingCat,项目名称:vscode-ghc-simple,代码行数:80,代码来源:range-type.ts

示例8: rangeByLine

 linesToJoin.forEach(line => {
     const range = rangeByLine(line);
     if (range) {
         ranges.push(range);
     }
 });
开发者ID:Beatusvir,项目名称:amVim-for-VSCode,代码行数:6,代码来源:JoinLines.ts


注:本文中的vscode.Range类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。