本文整理汇总了TypeScript中paperclip.parseModuleSource函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parseModuleSource函数的具体用法?TypeScript parseModuleSource怎么用?TypeScript parseModuleSource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseModuleSource函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getModuleId
export const getComponentsFromSourceContent = (content: string, filePath: string, state: ApplicationState): RegisteredComponent[] => {
const moduleId = getModuleId(filePath);
const result = parseModuleSource(content);
if (!result.root) {
console.warn(`Syntax error in ${filePath}`);
result.diagnostics.forEach((diagnostic) => {
console.log(diagnostic.message);
})
return [];
}
const module = loadModuleAST(result.root, filePath);
if (module.type !== PCModuleType.COMPONENT) {
return [];
}
return (module as ComponentModule).components.filter(component => !getComponentMetadataItem(component, ComponentMetadataName.INTERNAL)).map(({id, source, previews}) => ({
filePath,
label: id,
location: source.location,
$id: id,
screenshots: previews.map(preview => {
return getComponentScreenshot(id, preview.name, state)
}),
tagName: id,
moduleId: moduleId,
}));
};
开发者ID:cryptobuks,项目名称:tandem,代码行数:32,代码来源:index.ts
示例2: insertSnippet
function* insertSnippet(insertText) {
const editor = vscode.window.activeTextEditor;
const doc = editor.document;
const carretOffset = insertText.indexOf("%|");
insertText = insertText.replace("%|", "");
const docText = doc.getText();
const selection = editor.selection.active || doc.positionAt(docText.length);
const offset = doc.offsetAt(selection);
// smoke test first to make sure that the
const { diagnostics } = parseModuleSource(docText.substr(0, offset) + insertText + docText.substr(offset));
// We COULD just insert the snippet to the end of the document, but
// but it's probably better to fail here and notify the user so that they can correct _their_ mistake.
if (diagnostics.length) {
return false;
}
yield call(async () => {
return editor.edit((edit) => {
edit.insert(
selection,
insertText
);
});
});
if (carretOffset > -1) {
const newPos = doc.positionAt(offset + carretOffset);
editor.selection = new vscode.Selection(newPos, newPos);
}
return true;
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:35,代码来源:vscode.ts
示例3: parseModuleSource
return moduleFilePaths.map((filePath) => {
const result = parseModuleSource(read(filePath));
if (!result.root) {
return;
}
const module = loadModuleAST(result.root, filePath);
return module;
}).filter(Boolean);
开发者ID:cryptobuks,项目名称:tandem,代码行数:8,代码来源:index.ts
示例4: handleOpenCurrentFileInTandem
function* handleOpenCurrentFileInTandem() {
while(true) {
yield take(OPEN_CURRENT_FILE_IN_TANDEM_EXECUTED);
const state: ExtensionState = yield select();
if (!(yield call(checkCurrentFileIsPaperclip))) {
continue;
}
const activeTextEditor = vscode.window.activeTextEditor;
const filePath = activeTextEditor.document.uri.fsPath;
const { diagnostics, root } = parseModuleSource(activeTextEditor.document.getText(), filePath);
// just show one error for now
if (diagnostics.length) {
vscode.window.showErrorMessage(`Paperclip syntax error: ${diagnostics[0].message}`);
continue;
}
const module = loadModuleAST(root, filePath);
if (module.type === PCModuleType.COMPONENT && !(module as ComponentModule).components.length) {
const pick = yield call(async () => {
return await vscode.window.showInformationMessage("Could not find a component to open with in Tandem. Would you like to create one?", "Yes", "No");
});
if (pick === "Yes") {
yield put(insertNewComponentExecuted());
}
continue;
}
const selectedPreviewOptions: PreviewOption[] = yield call(pickComponentPreviews, module);
if (!selectedPreviewOptions.length) {
continue;
}
// null provided for default preview (first one)
const artboardInfo: ArtboardInfo[] = selectedPreviewOptions.map(({ component, preview }): ArtboardInfo => ({
componentId: component.id,
previewName: preview.name,
width: preview.width,
height: preview.height
}));
yield call(requestOpenTandemIfDisconnected);
yield put(openArtboardsRequested(artboardInfo));
}
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:49,代码来源:vscode.ts
示例5: doHover
export function doHover(
document: TextDocument,
position: Position,
tagProviders: IHTMLTagProvider[],
config: any,
devToolsPort
): Hover | Promise<Hover> {
const offset = document.offsetAt(position);
// console.log("DOCC");
const { root, diagnostics } = parseModuleSource(document.getText());
// console.log("PARSE MOD SOURCE" + JSON.stringify(root) + JSON.stringify(diagnostics, null, 2));
const expr = root && getExpressionAtPosition(offset, root, (expr) => {
return expr.type === PCExpressionType.SELF_CLOSING_ELEMENT || expr.type === PCExpressionType.ELEMENT;
});
if (!expr) {
return NULL_HOVER;
}
function getTagHover(element: PCSelfClosingElement|PCElement, range: Range, open: boolean): Hover | Promise<Hover> {
const startTag = element.type === PCExpressionType.SELF_CLOSING_ELEMENT ? (element as PCSelfClosingElement) : (element as PCElement).startTag;
const { name: tagName } = startTag;
const tagLower = tagName.toLowerCase();
if (tagLower === "preview") {
const ancestors = getAncestors(element, root);
const component = ancestors[0];
const id = getPCStartTagAttribute(component, "id");
const previewName = getPCStartTagAttribute(element, "name") || component.childNodes.indexOf(element);
if (!id) {
return NULL_HOVER;
}
const hoverFilePath = path.join(TMP_DIRECTORY, `${id.replace(/\-/g, "")}.png`);
return (async () => {
// Hack. Must save files to local FS for some reason.
try {
await new Promise((resolve, reject) => {
request({ url: `http://127.0.0.1:${devToolsPort}/components/${id}/screenshots/${previewName}/latest?maxWidth=300&maxHeight=240`, encoding: null }, (err, response, body) => {
if (err) return reject();
if (response.statusCode !== 200) {
return reject(new Error("not found"));
}
fs.writeFileSync(hoverFilePath, body);
resolve();
})
});
} catch(e) {
return {
contents: `Preview could not be loaded. `,
isTrusted: true
};
}
return {
// timestamp for cache buster
contents: `![component preview](file://${hoverFilePath}?${Date.now()})`
};
})();
}
for (const provider of tagProviders) {
let hover: Hover | null = null;
provider.collectTags((t, label) => {
if (t === tagLower) {
const tagLabel = open ? '<' + tagLower + '>' : '</' + tagLower + '>';
hover = { contents: [{ language: 'html', value: tagLabel }, MarkedString.fromPlainText(label)], range };
}
});
if (hover) {
return hover;
}
}
return NULL_HOVER;
}
function getAttributeHover(tag: string, attribute: string, range: Range): Hover {
tag = tag.toLowerCase();
let hover: Hover = NULL_HOVER;
for (const provider of tagProviders) {
provider.collectAttributes(tag, (attr, type, documentation) => {
if (attribute !== attr) {
return;
}
const contents = [documentation ? MarkedString.fromPlainText(documentation) : `No doc for ${attr}`];
hover = { contents, range };
});
}
return hover;
}
const range = exprLocationToRange(expr.location);
//.........这里部分代码省略.........
开发者ID:cryptobuks,项目名称:tandem,代码行数:101,代码来源:htmlHover.ts
注:本文中的paperclip.parseModuleSource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论