當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。