本文整理汇总了TypeScript中vscode.workspace.openTextDocument方法的典型用法代码示例。如果您正苦于以下问题:TypeScript workspace.openTextDocument方法的具体用法?TypeScript workspace.openTextDocument怎么用?TypeScript workspace.openTextDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.workspace
的用法示例。
在下文中一共展示了workspace.openTextDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('class methods', async () => {
if (!await isPython3) {
return;
}
let textDocument = await vscode.workspace.openTextDocument(filePep526);
await vscode.window.showTextDocument(textDocument);
assert(vscode.window.activeTextEditor, 'No active editor');
let position = new vscode.Position(20, 4);
let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'a').length, 0, 'method a not found');
position = new vscode.Position(21, 4);
list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
assert.notEqual(list.items.filter(item => item.label === 'b').length, 0, 'method b not found');
});
示例2: test
test('Get Code Block (for in)', done => {
let textDocument: vscode.TextDocument;
return vscode.workspace.openTextDocument(FILE_WITH_CELLS).then(document => {
textDocument = document;
return vscode.window.showTextDocument(textDocument);
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
editor.selection = new vscode.Selection(16, 0, 16, 0);
return codeHelper.getSelectedCode().then(code => {
const end = textDocument.lineAt(18).range.end;
const start = editor.selection.start;
assert.equal(code, textDocument.getText(new vscode.Range(start, end)), 'Text is not the same');
});
}).then(done, done);
});
示例3: showSource
function showSource(mdUri: vscode.Uri) {
if (!mdUri) {
return vscode.commands.executeCommand('workbench.action.navigateBack');
}
const docUri = vscode.Uri.parse(mdUri.query);
for (const editor of vscode.window.visibleTextEditors) {
if (editor.document.uri.toString() === docUri.toString()) {
return vscode.window.showTextDocument(editor.document, editor.viewColumn);
}
}
return vscode.workspace.openTextDocument(docUri)
.then(vscode.window.showTextDocument);
}
示例4: test
test('should correctly format ' + path.basename(inFile), () => {
let expectedText = fs.readFileSync(outFile);
let textDocument: vscode.TextDocument;
return vscode.workspace.openTextDocument(inFile).then(document => {
textDocument = document;
return formatService.provideDocumentFormattingEdits(document);
}).then(edits => {
let workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.set(textDocument.uri, edits);
return vscode.workspace.applyEdit(workspaceEdit);
}).then(() => {
assert.equal(textDocument.getText(), expectedText);
});
});
示例5: openFileInEditor
// Open the created component in the editor
public openFileInEditor(folderName): Q.Promise<TextEditor> {
const deferred: Q.Deferred<TextEditor> = Q.defer<TextEditor>();
var inputName: string = path.parse(folderName).name;;
var fullFilePath: string = path.join(folderName, `${inputName}.component.ts`);
workspace.openTextDocument(fullFilePath).then((textDocument) => {
if (!textDocument) { return; }
window.showTextDocument(textDocument).then((editor) => {
if (!editor) { return; }
deferred.resolve(editor);
});
});
return deferred.promise;
}
示例6: test
test('editor, assign and check view columns', () => {
return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => {
let p1 = window.showTextDocument(doc, ViewColumn.One).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.One);
});
let p2 = window.showTextDocument(doc, ViewColumn.Two).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.Two);
});
let p3 = window.showTextDocument(doc, ViewColumn.Three).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.Three);
});
return Promise.all([p1, p2, p3]);
});
});
示例7: onExecute
execute: () => {
this._client.logTelemetry('js.hintProjectExcludes.accepted');
onExecute();
this._item.hide();
let configFileUri: vscode.Uri;
if (vscode.workspace.rootPath && dirname(configFileName).indexOf(vscode.workspace.rootPath) === 0) {
configFileUri = vscode.Uri.file(configFileName);
} else {
configFileUri = vscode.Uri.parse('untitled://' + join(vscode.workspace.rootPath || '', 'jsconfig.json'));
}
return vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument);
}
示例8:
context.subscriptions.push(vscode.commands.registerCommand('_markdown.didClick', (uri: string, line) => {
const sourceUri = vscode.Uri.parse(decodeURIComponent(uri));
return vscode.workspace.openTextDocument(sourceUri)
.then(document => vscode.window.showTextDocument(document))
.then(editor =>
vscode.commands.executeCommand('revealLine', { lineNumber: Math.floor(line), at: 'center' })
.then(() => editor))
.then(editor => {
if (editor) {
editor.selection = new vscode.Selection(
new vscode.Position(Math.floor(line), 0),
new vscode.Position(Math.floor(line), 0));
}
});
}));
示例9: createRandomFile
return createRandomFile(initialContents).then(file => {
return vscode.workspace.openTextDocument(file).then(doc => {
return vscode.window.showTextDocument(doc).then((editor) => {
return run(editor, doc).then(_ => {
if (doc.isDirty) {
return doc.save().then(saved => {
return deleteFile(file);
});
} else {
return deleteFile(file);
}
});
});
});
});
示例10: openFile
@command('git.openFile')
async openFile(arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
const preserveFocus = arg instanceof Resource;
let uris: Uri[] | undefined;
if (arg instanceof Uri) {
if (arg.scheme === 'git') {
uris = [Uri.file(fromGitUri(arg).path)];
} else if (arg.scheme === 'file') {
uris = [arg];
}
} else {
let resource = arg;
if (!(resource instanceof Resource)) {
// can happen when called from a keybinding
resource = this.getSCMResource();
}
if (resource) {
uris = [...resourceStates.map(r => r.resourceUri), resource.resourceUri];
}
}
if (!uris) {
return;
}
const preview = uris.length === 1 ? true : false;
const activeTextEditor = window.activeTextEditor;
for (const uri of uris) {
const opts: TextDocumentShowOptions = {
preserveFocus,
preview,
viewColumn: ViewColumn.Active
};
// Check if active text editor has same path as other editor. we cannot compare via
// URI.toString() here because the schemas can be different. Instead we just go by path.
if (activeTextEditor && activeTextEditor.document.uri.path === uri.path) {
opts.selection = activeTextEditor.selection;
}
const document = await workspace.openTextDocument(uri);
await window.showTextDocument(document, opts);
}
}