本文整理匯總了TypeScript中vscode-emmet-helper.doComplete函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript doComplete函數的具體用法?TypeScript doComplete怎麽用?TypeScript doComplete使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了doComplete函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getStyleMode
function getStyleMode(
languageId: string,
languageService: LanguageService,
documentRegions: LanguageModelCache<PaperclipDocumentRegions>
): LanguageMode {
const embeddedDocuments = getLanguageModelCache(10, 60, document =>
documentRegions.get(document).getEmbeddedDocument(languageId)
);
const stylesheets = getLanguageModelCache(10, 60, document => languageService.parseStylesheet(document));
let config: any = {};
return {
getId() {
return languageId;
},
configure(c) {
languageService.configure(c && c.css);
config = c;
},
async doValidation(document) {
const embedded = embeddedDocuments.get(document);
return await languageService.doValidation(embedded, stylesheets.get(embedded));
},
doComplete(document, position) {
const embedded = embeddedDocuments.get(document);
const emmetCompletions: CompletionList = emmet.doComplete(document, position, languageId, {
useNewEmmet: true,
showExpandedAbbreviation: true,
showAbbreviationSuggestions: true,
syntaxProfiles: {},
variables: {}
});
const emmetItems = _.map(emmetCompletions.items, i => {
return {
...i,
sortText: Priority.Emmet + i.label
};
});
const lsCompletions = languageService.doComplete(embedded, position, stylesheets.get(embedded));
const lsItems = lsCompletions ? _.map(lsCompletions.items, i => {
return {
...i,
sortText: Priority.Platform + i.label
};
}) : [];
return {
isIncomplete: true,
items: _.concat(emmetItems, lsItems)
};
},
doHover(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.doHover(embedded, position, stylesheets.get(embedded)) || NULL_HOVER;
},
findDocumentHighlight(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentHighlights(embedded, position, stylesheets.get(embedded));
},
findDocumentSymbols(document) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentSymbols(embedded, stylesheets.get(embedded));
},
findDefinition(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findDefinition(embedded, position, stylesheets.get(embedded));
},
findReferences(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findReferences(embedded, position, stylesheets.get(embedded));
},
findDocumentColors(document) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentColors(embedded, stylesheets.get(embedded));
},
getColorPresentations(document, color, range) {
const embedded = embeddedDocuments.get(document);
return languageService.getColorPresentations(embedded, stylesheets.get(embedded), color, range);
},
format(document, currRange, formattingOptions) {
if (config.tandem.paperclip.format.defaultFormatter[languageId] === 'none') {
return [];
}
const { value, range } = getValueAndRange(document, currRange);
const needIndent = config.tandem.paperclip.format.styleInitialIndent;
const parserMap: { [k: string]: ParserOption } = {
css: 'css'
};
return prettierify(
value,
getFileFsPath(document.uri),
range,
needIndent,
formattingOptions,
config.prettier,
parserMap[languageId]
);
},
onDocumentRemoved(document) {
embeddedDocuments.onDocumentRemoved(document);
//.........這裏部分代碼省略.........
示例2: getStyleMode
function getStyleMode(
languageId: string,
languageService: LanguageService,
documentRegions: LanguageModelCache<VueDocumentRegions>
): LanguageMode {
const embeddedDocuments = getLanguageModelCache(10, 60, document =>
documentRegions.get(document).getEmbeddedDocument(languageId)
);
const stylesheets = getLanguageModelCache(10, 60, document => languageService.parseStylesheet(document));
let config: any = {};
return {
getId() {
return languageId;
},
configure(c) {
languageService.configure(c && c.css);
config = c;
},
doValidation(document) {
if (languageId === 'postcss') {
return [];
} else {
const embedded = embeddedDocuments.get(document);
return languageService.doValidation(embedded, stylesheets.get(embedded));
}
},
doComplete(document, position) {
const embedded = embeddedDocuments.get(document);
const emmetSyntax = languageId === 'postcss' ? 'css' : languageId;
const lsCompletions = languageService.doComplete(embedded, position, stylesheets.get(embedded));
const lsItems = lsCompletions ? _.map(lsCompletions.items, i => {
return {
...i,
sortText: Priority.Platform + i.label
};
}) : [];
const emmetCompletions = emmet.doComplete(document, position, emmetSyntax, config.emmet);
if (!emmetCompletions) {
return { isIncomplete: false, items: lsItems };
} else {
const emmetItems = _.map(emmetCompletions.items, i => {
return {
...i,
sortText: Priority.Emmet + i.label
};
});
return {
isIncomplete: emmetCompletions.isIncomplete,
items: _.concat(emmetItems, lsItems)
};
}
},
doHover(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.doHover(embedded, position, stylesheets.get(embedded)) || NULL_HOVER;
},
findDocumentHighlight(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentHighlights(embedded, position, stylesheets.get(embedded));
},
findDocumentSymbols(document) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentSymbols(embedded, stylesheets.get(embedded));
},
findDefinition(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findDefinition(embedded, position, stylesheets.get(embedded));
},
findReferences(document, position) {
const embedded = embeddedDocuments.get(document);
return languageService.findReferences(embedded, position, stylesheets.get(embedded));
},
findDocumentColors(document) {
const embedded = embeddedDocuments.get(document);
return languageService.findDocumentColors(embedded, stylesheets.get(embedded));
},
getColorPresentations(document, color, range) {
const embedded = embeddedDocuments.get(document);
return languageService.getColorPresentations(embedded, stylesheets.get(embedded), color, range);
},
format(document, currRange, formattingOptions) {
if (config.vetur.format.defaultFormatter[languageId] === 'none') {
return [];
}
const { value, range } = getValueAndRange(document, currRange);
const needIndent = config.vetur.format.styleInitialIndent;
const parserMap: { [k: string]: ParserOption } = {
css: 'css',
postcss: 'css',
scss: 'scss',
less: 'less'
};
return prettierify(
value,
getFileFsPath(document.uri),
range,
needIndent,
//.........這裏部分代碼省略.........
示例3: doComplete
export function doComplete(
document: TextDocument,
position: Position,
htmlDocument: HTMLDocument,
tagProviders: IHTMLTagProvider[],
emmetConfig: emmet.EmmetConfiguration
): CompletionList {
const result: CompletionList = {
isIncomplete: false,
items: []
};
const offset = document.offsetAt(position);
const node = htmlDocument.findNodeBefore(offset);
if (!node || node.isInterpolation) {
return result;
}
const text = document.getText();
const scanner = createScanner(text, node.start);
let currentTag: string;
let currentAttributeName: string;
function getReplaceRange(replaceStart: number, replaceEnd: number = offset): Range {
if (replaceStart > offset) {
replaceStart = offset;
}
return { start: document.positionAt(replaceStart), end: document.positionAt(replaceEnd) };
}
function collectOpenTagSuggestions(afterOpenBracket: number, tagNameEnd?: number): CompletionList {
const range = getReplaceRange(afterOpenBracket, tagNameEnd);
tagProviders.forEach(provider => {
const priority = provider.priority;
provider.collectTags((tag, label) => {
result.items.push({
label: tag,
kind: CompletionItemKind.Property,
documentation: label,
textEdit: TextEdit.replace(range, tag),
sortText: priority + tag,
insertTextFormat: InsertTextFormat.PlainText
});
});
});
return result;
}
function getLineIndent(offset: number) {
let start = offset;
while (start > 0) {
const ch = text.charAt(start - 1);
if ('\n\r'.indexOf(ch) >= 0) {
return text.substring(start, offset);
}
if (!isWhiteSpace(ch)) {
return null;
}
start--;
}
return text.substring(0, offset);
}
function collectCloseTagSuggestions(
afterOpenBracket: number,
matchingOnly: boolean,
tagNameEnd: number = offset
): CompletionList {
const range = getReplaceRange(afterOpenBracket, tagNameEnd);
const closeTag = isFollowedBy(text, tagNameEnd, ScannerState.WithinEndTag, TokenType.EndTagClose) ? '' : '>';
let curr = node;
while (curr) {
const tag = curr.tag;
if (tag && (!curr.closed || curr.endTagStart && (curr.endTagStart > offset))) {
const item: CompletionItem = {
label: '/' + tag,
kind: CompletionItemKind.Property,
filterText: '/' + tag + closeTag,
textEdit: TextEdit.replace(range, '/' + tag + closeTag),
insertTextFormat: InsertTextFormat.PlainText
};
const startIndent = getLineIndent(curr.start);
const endIndent = getLineIndent(afterOpenBracket - 1);
if (startIndent !== null && endIndent !== null && startIndent !== endIndent) {
const insertText = startIndent + '</' + tag + closeTag;
(item.textEdit = TextEdit.replace(getReplaceRange(afterOpenBracket - 1 - endIndent.length), insertText)),
(item.filterText = endIndent + '</' + tag + closeTag);
}
result.items.push(item);
return result;
}
curr = curr.parent;
}
if (matchingOnly) {
return result;
}
tagProviders.forEach(provider => {
provider.collectTags((tag, label) => {
result.items.push({
label: '/' + tag,
//.........這裏部分代碼省略.........
示例4: getStylusMode
export function getStylusMode(documentRegions: LanguageModelCache<VueDocumentRegions>): LanguageMode {
const embeddedDocuments = getLanguageModelCache(10, 60, document =>
documentRegions.get(document).getEmbeddedDocument('stylus')
);
let baseIndentShifted = false;
let config: any = {};
return {
getId: () => 'stylus',
configure(c) {
baseIndentShifted = _.get(c, 'vetur.format.styleInitialIndent', false);
config = c;
},
onDocumentRemoved() {},
dispose() {},
doComplete(document, position) {
const embedded = embeddedDocuments.get(document);
const lsCompletions = provideCompletionItems(embedded, position);
const lsItems = _.map(lsCompletions.items, i => {
return {
...i,
sortText: Priority.Platform + i.label
};
});
const emmetCompletions: CompletionList = emmet.doComplete(document, position, 'stylus', config.emmet);
if (!emmetCompletions) {
return { isIncomplete: false, items: lsItems };
} else {
const emmetItems = _.map(emmetCompletions.items, i => {
return {
...i,
sortText: Priority.Emmet + i.label
};
});
return {
isIncomplete: emmetCompletions.isIncomplete,
items: _.concat(emmetItems, lsItems)
};
}
},
findDocumentSymbols(document) {
const embedded = embeddedDocuments.get(document);
return provideDocumentSymbols(embedded);
},
doHover(document, position) {
const embedded = embeddedDocuments.get(document);
return stylusHover(embedded, position);
},
format(document, range, formatParams) {
if (config.vetur.format.defaultFormatter.stylus === 'none') {
return [];
}
const embedded = embeddedDocuments.get(document);
const inputText = embedded.getText();
const tabStopChar = formatParams.insertSpaces ? ' '.repeat(formatParams.tabSize) : '\t';
// Note that this would have been `document.eol` ideally
const newLineChar = inputText.includes('\r\n') ? '\r\n' : '\n';
// Determine the base indentation for the multi-line Stylus content
let baseIndent = '';
if (range.start.line !== range.end.line) {
const styleTagLine = document.getText().split(/\r?\n/)[range.start.line];
if (styleTagLine) {
baseIndent = _.get(styleTagLine.match(/^(\t|\s)+/), '0', '');
}
}
// Add one more indentation when `vetur.format.styleInitialIndent` is set to `true`
if (baseIndentShifted) {
baseIndent += tabStopChar;
}
// Build the formatting options for Stylus Supremacy
// See https://thisismanta.github.io/stylus-supremacy/#options
const stylusSupremacyFormattingOptions = StylusSupremacy.createFormattingOptions(config.stylusSupremacy || {});
const formattingOptions = {
...stylusSupremacyFormattingOptions,
tabStopChar,
newLineChar: '\n'
};
const formattedText = StylusSupremacy.format(inputText, formattingOptions);
// Add the base indentation and correct the new line characters
const outputText = ((range.start.line !== range.end.line ? '\n' : '') + formattedText)
.split(/\n/)
.map(line => (line.length > 0 ? baseIndent + line : ''))
.join(newLineChar);
return [TextEdit.replace(range, outputText)];
}
};
}