本文整理匯總了TypeScript中vscode.Range.contains方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Range.contains方法的具體用法?TypeScript Range.contains怎麽用?TypeScript Range.contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.Range
的用法示例。
在下文中一共展示了Range.contains方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
});
示例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);
}
示例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);
}
});
示例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;
}
示例5: 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')];
}
}
}