本文整理匯總了TypeScript中vscode.Uri類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Uri類的具體用法?TypeScript Uri怎麽用?TypeScript Uri使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Uri類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('addUniqueDiagnostic adds the diagnostic to the empty diagnostics', () => {
const diagnostic: FileDiagnostic = {
filePath: '/1',
diagnostic: new Diagnostic(new Range(1, 2, 3, 4), 'Hello', undefined)
};
const diagnostics = languages.createDiagnosticCollection('rust');
addUniqueDiagnostic(diagnostic, diagnostics);
const fileDiagnostics = diagnostics.get(Uri.file('/1'));
if (!fileDiagnostics) {
assert.notEqual(fileDiagnostics, undefined);
} else {
assert.equal(fileDiagnostics.length, 1);
}
});
示例2: openChange
@command('git.openChange')
async openChange(uri: Uri): Promise<void> {
const scmResource = resolveGitResource(uri);
if (scmResource) {
return await this.open(scmResource);
}
if (uri.scheme === 'file') {
const uriString = uri.toString();
const resource = this.model.workingTreeGroup.resources.filter(r => r.uri.toString() === uriString)[0]
|| this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString)[0];
if (resource) {
return await this.open(resource);
}
}
}
示例3: it
it("should call update method of previewManager with correct parameters", sinon.test(function () {
let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", function () {
ExtensionConstants.EXTENSION_TYPE = ExtensionConstants.VSC_EXTENSION;
return true;
})
let previewManagerStub = sinon.createStubInstance(dummyPreviewManager);
previewManagerController = new PreviewManagerController(utilities, previewManagerStub, previewManagerStub);
previewManagerController.onEvent();
sinon.assert.calledOnce(checkExtensionTypeStub);
expect(previewManagerController.previewManager).to.equal(previewManagerStub);
sinon.assert.calledOnce(previewManagerStub.generatePreview);
sinon.assert.calledOnce(previewManagerStub.update);
sinon.assert.calledWith(previewManagerStub.update,vscode.Uri.parse(ExtensionConstants.PREVIEW_URI))
}))
示例4: createTempDocument
export function createTempDocument(content?: string) {
const uri = Uri.parse(`untitled:${__dirname}.${Math.random()}.tmp`);
return workspace.openTextDocument(uri)
.then(document => {
return window.showTextDocument(document);
})
.then(() => {
if (content) {
window.activeTextEditor.edit(editBuilder => {
editBuilder.insert(new Position(0, 0), content);
});
}
return window.activeTextEditor;
});
}
示例5: setupWorkspace
export async function setupWorkspace(
config: IConfiguration = new Configuration(),
fileExtension: string = ''
): Promise<any> {
const filePath = await createRandomFile('', fileExtension);
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
await vscode.window.showTextDocument(doc);
Globals.mockConfiguration = config;
reloadConfiguration();
let activeTextEditor = vscode.window.activeTextEditor;
assert.ok(activeTextEditor);
activeTextEditor!.options.tabSize = config.tabstop;
activeTextEditor!.options.insertSpaces = config.expandtab;
}
示例6: activate
export function activate(context: vscode.ExtensionContext) {
let previewUri = vscode.Uri.parse('html-preview://html-preview');
class MyTextDocumentContentProvider implements vscode.TextDocumentContentProvider {
public provideTextDocumentContent(uri: vscode.Uri): string {
return this.displayHtml();
}
private displayHtml() {
var renderer = new marked.Renderer();
renderer.heading = function (text, level) {
return '<h' + level + '>' + text + '</h' + level + '>';
};
let editor = vscode.window.activeTextEditor;
if (editor.document.languageId === 'markdown') {
let text = editor.document.getText();
let htmlText = encode(marked(text, {renderer:renderer}));
return htmlText;
}
else {
return null;
}
}
}
let provider = new MyTextDocumentContentProvider();
let registration = vscode.workspace.registerTextDocumentContentProvider('html-preview', provider);
let disposable = vscode.commands.registerCommand('extension.previewHtml', () => {
return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two).then((success) => {
}, (reason) => {
vscode.window.showErrorMessage(reason);
});
});
context.subscriptions.push(disposable);
}
示例7: manageIncludes
export async function manageIncludes(uri: Uri, opened: boolean) {
const key = uri.toString()
if (opened) {
const include = includes.get(key)
if (isString(include)) return
const server = fromUri(uri)
const obj = await server.findAbapObject(uri)
if (obj.type !== "PROG/I") includes.set(key, "")
else {
let main = ""
try {
main = await await server.activator.selectMain(obj)
} finally {
includes.set(key, main || "")
// if(main)
}
}
} else includes.delete(key)
}
示例8: it
it("Flutter: New Project can be invoked and creates trigger file", async () => {
const showInputBox = sb.stub(vs.window, "showInputBox");
showInputBox.resolves("my_test_flutter_proj");
const showOpenDialog = sb.stub(vs.window, "showOpenDialog");
const tempFolder = getRandomTempFolder();
showOpenDialog.resolves([vs.Uri.file(tempFolder)]);
// Intercept executeCommand for openFolder so we don't spawn a new instance of Code!
const executeCommand = sb.stub(vs.commands, "executeCommand").callThrough();
const openFolder = executeCommand.withArgs("vscode.openFolder", sinon.match.any).resolves();
await vs.commands.executeCommand("flutter.createProject");
assert.ok(showInputBox.calledOnce);
assert.ok(showOpenDialog.calledOnce);
assert.ok(openFolder.calledOnce);
assert.ok(fs.existsSync(path.join(tempFolder, "my_test_flutter_proj", FLUTTER_CREATE_PROJECT_TRIGGER_FILE)));
});
示例9: openOrCreateConfigFile
export async function openOrCreateConfigFile(
isTypeScriptProject: boolean,
rootPath: string,
config: TypeScriptServiceConfiguration
): Promise<vscode.TextEditor | null> {
const configFile = vscode.Uri.file(path.join(rootPath, isTypeScriptProject ? 'tsconfig.json' : 'jsconfig.json'));
const col = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
try {
const doc = await vscode.workspace.openTextDocument(configFile);
return vscode.window.showTextDocument(doc, col);
} catch {
const doc = await vscode.workspace.openTextDocument(configFile.with({ scheme: 'untitled' }));
const editor = await vscode.window.showTextDocument(doc, col);
if (editor.document.getText().length === 0) {
await editor.insertSnippet(inferredProjectConfigSnippet(config));
}
return editor;
}
}
示例10: test
test('registerTextDocumentContentProvider, change event', function() {
let callCount = 0;
let listeners: Function[] = [];
let registration = workspace.registerTextDocumentContentProvider('foo', {
onDidChange(callback, thisArg, disposables) {
let actual = thisArg ? callback.bind(thisArg) : callback;
listeners.push(actual);
let subscription = new Disposable(() => {
const idx = listeners.indexOf(actual);
listeners.splice(idx, 1);
});
if (Array.isArray(disposables)) {
disposables.push(subscription);
}
return subscription;
},
provideTextDocumentContent(uri) {
return 'call' + (callCount++);
}
});
const uri = Uri.parse('foo://testing/path2');
return workspace.openTextDocument(uri).then(doc => {
assert.equal(callCount, 1);
assert.equal(doc.getText(), 'call0');
return new Promise((resolve, reject) => {
workspace.onDidChangeTextDocument(event => {
assert.ok(event.document === doc);
assert.equal(event.document.getText(), 'call1');
resolve();
});
listeners.forEach(l => l(doc.uri));
registration.dispose();
});
});
});