本文整理汇总了TypeScript中vscode.TextDocument.positionAt方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextDocument.positionAt方法的具体用法?TypeScript TextDocument.positionAt怎么用?TypeScript TextDocument.positionAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.TextDocument
的用法示例。
在下文中一共展示了TextDocument.positionAt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getWindowsLineEndingCount
export function getWindowsLineEndingCount(document: TextDocument, offset: Number) {
const eolPattern = new RegExp('\r\n', 'g');
const readBlock = 1024;
let count = 0;
let offsetDiff = offset.valueOf();
// In order to prevent the one-time loading of large files from taking up too much memory
for (let pos = 0; pos < offset; pos += readBlock) {
let startAt = document.positionAt(pos);
let endAt = null;
if (offsetDiff >= readBlock) {
endAt = document.positionAt(pos + readBlock);
offsetDiff = offsetDiff - readBlock;
} else {
endAt = document.positionAt(pos + offsetDiff);
}
let text = document.getText(new Range(startAt, endAt));
let cr = text.match(eolPattern);
count += cr ? cr.length : 0;
}
return count;
}
示例2: provideCompletionItems
public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Thenable<CompletionList> {
let fileName = basename(document.fileName);
let currentWord = this.getCurrentWord(document, position);
let overwriteRange : Range;
let items: CompletionItem[] = [];
let isIncomplete = false;
let offset = document.offsetAt(position);
let location = getLocation(document.getText(), offset);
let node = location.previousNode;
if (node && node.offset <= offset && offset <= node.offset + node.length && (node.type === 'property' || node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
overwriteRange = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
} else {
overwriteRange = new Range(document.positionAt(offset - currentWord.length), position);
}
let filterText = document.getText(new Range(overwriteRange.start, position));
let proposed: { [key: string]: boolean } = {};
let collector: ISuggestionsCollector = {
add: (suggestion: CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
suggestion.textEdit = TextEdit.replace(overwriteRange, suggestion.insertText);
suggestion.filterText = filterText;
items.push(suggestion);
}
},
setAsIncomplete: () => isIncomplete = true,
error: (message: string) => console.error(message),
log: (message: string) => console.log(message)
};
let collectPromise : Thenable<any> = null;
if (location.isAtPropertyKey) {
let addValue = !location.previousNode || !location.previousNode.columnOffset;
let isLast = this.isLast(document, position);
collectPromise = this.jsonContribution.collectPropertySuggestions(fileName, location, currentWord, addValue, isLast, collector);
} else {
if (location.path.length === 0) {
collectPromise = this.jsonContribution.collectDefaultSuggestions(fileName, collector);
} else {
collectPromise = this.jsonContribution.collectValueSuggestions(fileName, location, collector);
}
}
if (collectPromise) {
return collectPromise.then(() => {
if (items.length > 0) {
return new CompletionList(items, isIncomplete);
}
return null;
});
}
return null;
}
示例3: getDiagnostic
function getDiagnostic(document: TextDocument, report: NpmListReport, moduleName: string, ranges: SourceRanges): Diagnostic {
let diagnostic = null;
// npm list only reports errors against 'dependencies' and not against 'devDependencies'
if (report.dependencies && report.dependencies[moduleName]) {
if (report.dependencies[moduleName]['missing'] === true) {
if (ranges.dependencies[moduleName]) {
const source = ranges.dependencies[moduleName].name;
const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
diagnostic = new Diagnostic(range, `Module '${moduleName}' is not installed`, DiagnosticSeverity.Warning);
} else {
console.log(`[npm-script] Could not locate "missing" dependency '${moduleName}' in package.json`);
}
}
else if (report.dependencies[moduleName]['invalid'] === true) {
if (ranges.dependencies[moduleName]) {
const source = ranges.dependencies[moduleName].version;
const installedVersion = report.dependencies[moduleName]['version'];
const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
const message = installedVersion ?
`Module '${moduleName}' the installed version '${installedVersion}' is invalid` :
`Module '${moduleName}' the installed version is invalid or has errors`;
diagnostic = new Diagnostic(range, message, DiagnosticSeverity.Warning);
} else {
console.log(`[npm-script] Could not locate "invalid" dependency '${moduleName}' in package.json`);
}
}
else if (report.dependencies[moduleName]['extraneous'] === true) {
const source = findAttributeRange(ranges);
const range = new Range(document.positionAt(source.offset), document.positionAt(source.offset + source.length));
diagnostic = new Diagnostic(range, `Module '${moduleName}' is extraneous`, DiagnosticSeverity.Warning);
}
}
return diagnostic;
}
示例4: buildOccurrences
private buildOccurrences(
highlights: DocumentHighlight[], document: TextDocument, position: number, occurrences: as.Occurrences
) {
let element = occurrences.element;
let offsets: number[] = occurrences.offsets;
let length: number = occurrences.length;
for (let i = 0; i < offsets.length; i++) {
let offset = offsets[i];
// Look for a match in any of the occurance ranges.
if ((offset <= position) && (position < (offset + length))) {
// If we get a match, then create highlights for all the items in the matching occurance.
for (let i = 0; i < offsets.length; i++) {
let offset = offsets[i];
let range = new Range(
document.positionAt(offset),
document.positionAt(offset + length)
);
highlights.push(new DocumentHighlight(range));
}
return;
}
}
}
示例5: Range
return bat.errors.filter(x => x.node).map(error => {
var startPos = doc.positionAt(error.node.startPosition);
var endPos = doc.positionAt(error.node.endPosition);
var decoration = {
range: new Range(startPos, endPos),
hoverMessage: error.toString()
};
return decoration;
});
示例6: getRange
private getRange(document: TextDocument, outline: as.Outline): Range {
// The outline's location includes whitespace before the block but the elements
// location only includes the small range declaring the element. To give the best
// experience to the user (perfectly highlight the range) we take the start point
// from the element but the end point from the outline.
let startPos = document.positionAt(outline.element.location.offset);
let endPos = document.positionAt(outline.offset + outline.length);
return new Range(startPos, endPos);
}
示例7: getTodos
public static getTodos(doc: TextDocument): model.TodoItem[] {
let docContent = doc.getText();
let regex = new rg.RegexFactory(doc.languageId).get();
/* For no reason, vscode returns duplicates matches sometimes.
To avoid that, check if a new item exists in the set */
let set = new collections.Set<model.TodoItem>();
let results: model.TodoItem[] = [];
if (docContent != "") {
let match, indices = [];
while (match = regex.exec(docContent)) {
indices.push(match.index);
let matched_text = (match[1]) ? match[1] : match[0];
let filter_result = this.filter(this.cleanString(matched_text));
matched_text = filter_result[0];
if(!matched_text) { // there is no todo
continue;
}
let skipped = filter_result[1];
let id = match.index + skipped;
let range = new Range(doc.positionAt(id), doc.positionAt(id + matched_text.length));
let new_item = new model.TodoItem(range, matched_text, doc.fileName);
if (!set.contains(new_item)) {
results.push(new_item);
set.add(new_item);
}
}
}
return results;
}
示例8: toDecorationRange
public toDecorationRange(start: number, document: TextDocument): Range {
const pos = document.positionAt(start);
const line = pos.line;
const documentLine = document.lineAt(line);
const lineRange = documentLine.range;
return new Range(lineRange.end.line, lineRange.end.character, lineRange.end.line, lineRange.end.character);
}
示例9: resolve
}).then(resp => {
if (resp.hovers.length == 0) {
resolve(null);
} else {
let hover = resp.hovers[0];
let markdown = this.getHoverData(hover);
if (markdown) {
let range = new Range(
document.positionAt(hover.offset),
document.positionAt(hover.offset + hover.length)
);
resolve(new Hover(markdown, range));
} else {
resolve(null);
}
}
});
示例10: 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);
}
});