本文整理匯總了TypeScript中vscode-uri.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了parse函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getFilePath
export function getFilePath(documentUri: string): string {
const IS_WINDOWS = platform() === 'win32';
if (IS_WINDOWS) {
// Windows have a leading slash like /C:/Users/pine
return Uri.parse(documentUri).path.slice(1);
} else {
return Uri.parse(documentUri).path;
}
}
示例2: getUri
export function getUri(fullpath: string, id: number, buftype: string): string {
if (!fullpath) return `untitled:${id}`
if (path.isAbsolute(fullpath)) return Uri.file(fullpath).toString()
if (isuri.isValid(fullpath)) return Uri.parse(fullpath).toString()
if (buftype != '') return `${buftype}:${id}`
return `unknown:${id}`
}
示例3: resolveWorkspaceRoot
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: WorkspaceFolder[]): string | undefined {
for (let i = 0; i < workspaceFolders.length; i++) {
if (startsWith(activeDoc.uri, workspaceFolders[i].uri)) {
return path.resolve(URI.parse(workspaceFolders[i].uri).fsPath);
}
}
}
示例4:
export function ensureLeadingDot<T extends string>(href: T): T {
if (!Uri.parse(href).scheme &&
!(href.startsWith('./') || href.startsWith('../'))) {
return './' + href as T;
}
return href;
}
示例5: it
it('should fire onWillSaveUntil', async () => {
let doc = await helper.createDocument()
let filepath = Uri.parse(doc.uri).fsPath
let fn = jest.fn()
let disposable = workspace.onWillSaveUntil(event => {
let promise = new Promise<TextEdit[]>(resolve => {
fn()
let edit: TextEdit = {
newText: 'foo',
range: Range.create(0, 0, 0, 0)
}
resolve([edit])
})
event.waitUntil(promise)
}, null, 'test')
await helper.wait(100)
await nvim.setLine('bar')
await helper.wait(30)
await events.fire('BufWritePre', [doc.bufnr])
await helper.wait(30)
let content = doc.getDocumentContent()
expect(content.startsWith('foobar')).toBe(true)
disposable.dispose()
expect(fn).toBeCalledTimes(1)
if (fs.existsSync(filepath)) {
fs.unlinkSync(filepath)
}
})
示例6: getFormatter
function getFormatter(
document: TextDocument,
env: IEnvironment,
config: RubyConfiguration,
range?: Range
): IFormatter {
if (typeof config.format === 'string') {
const formatterConfig: FormatterConfig = {
env,
executionRoot: URI.parse(config.workspaceFolderUri).fsPath,
config: {
command: config.format,
useBundler: config.useBundler,
},
};
if (range) {
formatterConfig.range = range;
}
return new FORMATTER_MAP[config.format](document, formatterConfig);
} else {
return new NullFormatter();
}
}
示例7: providePathSuggestions
function providePathSuggestions(pathValue: string, position: Position, range: Range, document: TextDocument, workspaceFolders: WorkspaceFolder[]) {
const fullValue = stripQuotes(pathValue);
const isValueQuoted = startsWith(pathValue, `'`) || startsWith(pathValue, `"`);
const valueBeforeCursor = isValueQuoted
? fullValue.slice(0, position.character - (range.start.character + 1))
: fullValue.slice(0, position.character - range.start.character);
const workspaceRoot = resolveWorkspaceRoot(document, workspaceFolders);
const currentDocFsPath = URI.parse(document.uri).fsPath;
const paths = providePaths(valueBeforeCursor, currentDocFsPath, workspaceRoot)
.filter(p => {
// Exclude current doc's path
return path.resolve(currentDocFsPath, '../', p) !== currentDocFsPath;
})
.filter(p => {
// Exclude paths that start with `.`
return p[0] !== '.';
});
const fullValueRange = isValueQuoted ? shiftRange(range, 1, -1) : range;
const replaceRange = pathToReplaceRange(valueBeforeCursor, fullValue, fullValueRange);
const suggestions = paths.map(p => pathToSuggestion(p, replaceRange));
return suggestions;
}
示例8: createLink
function createLink(
document: TextDocument,
documentContext: DocumentContext,
attributeValue: string,
startOffset: number,
endOffset: number,
base: string
): DocumentLink | null {
const documentUri = Uri.parse(document.uri);
const tokenContent = stripQuotes(attributeValue);
if (tokenContent.length === 0) {
return null;
}
if (tokenContent.length < attributeValue.length) {
startOffset++;
endOffset--;
}
const workspaceUrl = getWorkspaceUrl(documentUri, tokenContent, documentContext, base);
if (!workspaceUrl || !isValidURI(workspaceUrl)) {
return null;
}
return {
range: Range.create(document.positionAt(startOffset), document.positionAt(endOffset)),
target: workspaceUrl
};
}
示例9:
export function ensureLeadingDot<T>(href: T): T {
const hrefString = href as any as string;
if (!Uri.parse(hrefString).scheme &&
!(hrefString.startsWith('./') || hrefString.startsWith('../'))) {
return './' + href as any as T;
}
return href;
}