本文整理匯總了TypeScript中jsonc-parser.getLocation函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getLocation函數的具體用法?TypeScript getLocation怎麽用?TypeScript getLocation使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getLocation函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: provideCompletionItems
public provideCompletionItems(position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CompletionItem[]> {
const location = getLocation(this.document.getText(), this.document.offsetAt(position));
const range = this.document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
// window.title
if (location.path[0] === 'window.title') {
return this.provideWindowTitleCompletionItems(location, range);
}
// files.association
if (location.path[0] === 'files.associations') {
return this.provideFilesAssociationsCompletionItems(location, range);
}
// files.exclude, search.exclude
if (location.path[0] === 'files.exclude' || location.path[0] === 'search.exclude') {
return this.provideExcludeCompletionItems(location, range);
}
// files.defaultLanguage
if (location.path[0] === 'files.defaultLanguage') {
return this.provideLanguageCompletionItems(location, range);
}
return this.provideLanguageOverridesCompletionItems(location, position);
}
示例2: activate
export function activate(context) {
const commands = vscode.commands.getCommands(true);
//keybindings.json command-suggestions
const disposable = vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (location.path[1] === 'command') {
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
return commands.then(ids => ids.map(id => {
const item = new vscode.CompletionItem(`"${id}"`);
item.kind = vscode.CompletionItemKind.Value;
item.textEdit = {
range,
newText: item.label
};
return item;
}));
}
}
});
context.subscriptions.push(disposable);
}
示例3: 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;
}
示例4: registerExtensionsCompletions
function registerExtensionsCompletions(): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
if (location.path[0] === 'recommendations') {
const config = parse(document.getText());
const alreadyEnteredExtensions = config && config.recommendations || [];
if (Array.isArray(alreadyEnteredExtensions)) {
return vscode.extensions.all
.filter(e => !(
e.id.startsWith('vscode.')
|| e.id === 'Microsoft.vscode-markdown'
|| alreadyEnteredExtensions.indexOf(e.id) > -1
))
.map(e => {
const item = new vscode.CompletionItem(e.id);
const insertText = `"${e.id}"`;
item.kind = vscode.CompletionItemKind.Value;
item.insertText = insertText;
item.range = range;
item.filterText = insertText;
return item;
});
}
}
return [];
}
});
}
示例5: provideCompletionItems
public provideCompletionItems(position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.CompletionItem[]> {
const location = getLocation(this.document.getText(), this.document.offsetAt(position));
if (location.path.length >= 2 && location.path[1] === 'configurationDefaults') {
return this.provideLanguageOverridesCompletionItems(location, position);
}
}
示例6: provideCompletionItems
public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionList> {
let currentWord = this.getCurrentWord(document, position);
let overwriteRange = null;
let items: vscode.CompletionItem[] = [];
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 vscode.Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
} else {
overwriteRange = new vscode.Range(document.positionAt(offset - currentWord.length), position);
}
let proposed: { [key: string]: boolean } = {};
let collector: ISuggestionsCollector = {
add: (suggestion: vscode.CompletionItem) => {
if (!proposed[suggestion.label]) {
proposed[suggestion.label] = true;
if (overwriteRange) {
suggestion.textEdit = vscode.TextEdit.replace(overwriteRange, suggestion.insertText);
}
items.push(suggestion);
}
},
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 && (offset == (location.previousNode.offset + location.previousNode.length));
let scanner = createScanner(document.getText(), true);
scanner.setPosition(offset);
scanner.scan();
let isLast = scanner.getToken() === SyntaxKind.CloseBraceToken || scanner.getToken() === SyntaxKind.EOF;
collectPromise = this.jsonContribution.collectPropertySuggestions(document.fileName, location, currentWord, addValue, isLast, collector);
} else if (location.path.length !== 0)
collectPromise = this.jsonContribution.collectValueSuggestions(document.fileName, location, collector);
if (collectPromise) {
return collectPromise.then(() => {
if (items.length > 0) {
return new vscode.CompletionList(items);
}
return null;
});
}
return null;
}
示例7: registerKeybindingsCompletions
function registerKeybindingsCompletions(): vscode.Disposable {
const commands = vscode.commands.getCommands(true);
return vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (location.path[1] === 'command') {
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
return commands.then(ids => ids.map(id => newCompletionItem(id, range)));
}
}
});
}
示例8: activate
export function activate(context) {
const commands = vscode.commands.getCommands(true);
//keybindings.json command-suggestions
const disposable = vscode.languages.registerCompletionItemProvider({ pattern: '**/keybindings.json' }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (location.path[1] === 'command') {
return commands.then(ids => ids.map(id => new vscode.CompletionItem(id, vscode.CompletionItemKind.Value)));
}
}
});
context.subscriptions.push(disposable);
}
示例9: provideHover
public provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.Hover> {
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) {
let promise = this.jsonContribution.getInfoContribution(document.fileName, location);
if (promise) {
return promise.then(htmlContent => {
let range = new vscode.Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
let result: vscode.Hover = {
contents: htmlContent,
range: range
};
return result;
});
}
}
return null;
}
示例10: provideHover
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): Thenable<Hover> | null {
const fileName = basename(document.fileName);
const offset = document.offsetAt(position);
const location = getLocation(document.getText(), offset);
if (!location.previousNode) {
return null;
}
const node = location.previousNode;
if (node && node.offset <= offset && offset <= node.offset + node.length) {
const promise = this.jsonContribution.getInfoContribution(fileName, location);
if (promise) {
return promise.then(htmlContent => {
const range = new Range(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
const result: Hover = {
contents: htmlContent || [],
range: range
};
return result;
});
}
}
return null;
}