本文整理汇总了TypeScript中vscode.workspace.onDidOpenTextDocument方法的典型用法代码示例。如果您正苦于以下问题:TypeScript workspace.onDidOpenTextDocument方法的具体用法?TypeScript workspace.onDidOpenTextDocument怎么用?TypeScript workspace.onDidOpenTextDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.workspace
的用法示例。
在下文中一共展示了workspace.onDidOpenTextDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activate
export function activate(context: vscode.ExtensionContext) {
console.log("Activating extension Matlab");
var matlabConfig = workspace.getConfiguration('matlab');
if (!matlabConfig['lintOnSave']) {
return;
}
if (!matlabConfig.has('mlintpath') || matlabConfig['mlintpath'] == null) {
window.showErrorMessage("Could not find path to the mlint executable in the configuration file.")
return;
}
var mlintPath = matlabConfig['mlintpath'];
if (!fs.existsSync(mlintPath)) {
window.showErrorMessage("The cannot find mlint at the given path, please check your configuration file.")
return;
}
diagnosticCollection = vscode.languages.createDiagnosticCollection("matlab");
context.subscriptions.push(diagnosticCollection);
context.subscriptions.push(workspace.onDidSaveTextDocument(document => {lintDocument(document, mlintPath)}));
context.subscriptions.push(workspace.onDidOpenTextDocument(document => {lintDocument(document, mlintPath)}));
}
示例2: activate
export function activate(activationEventOccurred: boolean): void {
if (realActivationOccurred) {
return; // Occurs if multiple delayed commands occur before the real commands are registered.
}
// Activate immediately if an activation event occurred in the previous workspace session.
// If onActivationEvent doesn't occur, it won't auto-activate next time.
activatedPreviously = new PersistentWorkspaceState("activatedPreviously", false);
if (activatedPreviously.Value) {
activatedPreviously.Value = false;
realActivation();
}
if (tempCommands.length === 0) { // Only needs to be added once.
tempCommands.push(vscode.workspace.onDidOpenTextDocument(d => onDidOpenTextDocument(d)));
}
// Check if an activation event has already occurred.
if (activationEventOccurred) {
onActivationEvent();
return;
}
taskProvider = vscode.tasks.registerTaskProvider(taskSourceStr, {
provideTasks: () => {
return getBuildTasks(false);
},
resolveTask(task: vscode.Task): vscode.Task {
// Currently cannot implement because VS Code does not call this. Can implement custom output file directory when enabled.
return undefined;
}
});
vscode.tasks.onDidStartTask(event => {
if (event.execution.task.source === taskSourceStr) {
telemetry.logLanguageServerEvent('buildTaskStarted');
}
});
// handle "workspaceContains:/.vscode/c_cpp_properties.json" activation event.
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
for (let i: number = 0; i < vscode.workspace.workspaceFolders.length; ++i) {
let config: string = path.join(vscode.workspace.workspaceFolders[i].uri.fsPath, ".vscode/c_cpp_properties.json");
if (fs.existsSync(config)) {
onActivationEvent();
return;
}
}
}
// handle "onLanguage:cpp" and "onLanguage:c" activation events.
if (vscode.workspace.textDocuments !== undefined && vscode.workspace.textDocuments.length > 0) {
for (let i: number = 0; i < vscode.workspace.textDocuments.length; ++i) {
let document: vscode.TextDocument = vscode.workspace.textDocuments[i];
if (document.languageId === "cpp" || document.languageId === "c") {
onActivationEvent();
return;
}
}
}
}
示例3: getDiagnostics
const startLinting = (context: ExtensionContext): void => {
const diagnostics = vscode.languages.createDiagnosticCollection("fish");
context.subscriptions.push(diagnostics);
const lint = (document: TextDocument) => {
if (isSavedFishDocument(document)) {
return getDiagnostics(document)
.catch((error) => {
vscode.window.showErrorMessage(error.toString());
diagnostics.delete(document.uri);
})
// tslint:disable-next-line:readonly-array
.then((d) => diagnostics.set(document.uri, d as Diagnostic[]));
} else {
Promise.resolve();
}
};
vscode.workspace.onDidOpenTextDocument(lint, null, context.subscriptions);
vscode.workspace.onDidSaveTextDocument(lint, null, context.subscriptions);
vscode.workspace.textDocuments.forEach(lint);
// Remove diagnostics for closed files
vscode.workspace.onDidCloseTextDocument(
(d) => diagnostics.delete(d.uri), null, context.subscriptions);
};
示例4: trackFutureVirtualDocuments
function trackFutureVirtualDocuments(server: OmniSharpServer, eventStream: EventStream): IDisposable {
let onTextDocumentOpen = workspace.onDidOpenTextDocument(async document => {
if (shouldIgnoreDocument(document, server)) {
return;
}
await openVirtualDocument(document, server, eventStream);
});
let onTextDocumentChange = workspace.onDidChangeTextDocument(async changeEvent => {
const document = changeEvent.document;
if (shouldIgnoreDocument(document, server)) {
return;
}
await changeVirtualDocument(document, server, eventStream);
});
let onTextDocumentClose = workspace.onDidCloseTextDocument(async document => {
if (shouldIgnoreDocument(document, server)) {
return;
}
await closeVirtualDocument(document, server, eventStream);
});
// We already track text document changes for virtual documents in our change forwarder.
return new CompositeDisposable(
onTextDocumentOpen,
onTextDocumentClose,
onTextDocumentChange);
}
示例5: activate
export function activate(context: ExtensionContext) {
console.log("Write-Good Linter active...");
diagnosticCollection = languages.createDiagnosticCollection("Write-Good Lints");
diagnosticMap = new Map();
function isWriteGoodLanguage(languageId) {
let wgLanguages: string = workspace.getConfiguration('write-good').get('languages');
return (wgLanguages.indexOf(languageId) > -1 || wgLanguages === '*');
}
context.subscriptions.push(workspace.onDidChangeTextDocument(event => {
if (isWriteGoodLanguage(event.document.languageId)) {
doLint(event.document);
}
}));
context.subscriptions.push(workspace.onDidOpenTextDocument(event => {
if (isWriteGoodLanguage(event.languageId)) {
doLint(event);
}
}));
context.subscriptions.push(workspace.onDidCloseTextDocument(event => {
if (diagnosticMap.has(event.uri.toString())) {
diagnosticMap.delete(event.uri.toString());
}
resetDiagnostics();
}));
}
示例6: activate
export function activate(activationEventOccurred: boolean): void {
console.log("activating extension");
// Activate immediately if an activation event occurred in the previous workspace session.
// If onActivationEvent doesn't occur, it won't auto-activate next time.
activatedPreviously = new PersistentWorkspaceState("activatedPreviously", false);
if (activatedPreviously.Value) {
activatedPreviously.Value = false;
realActivation();
}
registerCommands();
tempCommands.push(vscode.workspace.onDidOpenTextDocument(d => onDidOpenTextDocument(d)));
// Check if an activation event has already occurred.
if (activationEventOccurred) {
return onActivationEvent();
}
if (vscode.workspace.textDocuments !== undefined && vscode.workspace.textDocuments.length > 0) {
for (let i: number = 0; i < vscode.workspace.textDocuments.length; ++i) {
let document: vscode.TextDocument = vscode.workspace.textDocuments[i];
if (document.languageId == "cpp" || document.languageId == "c") {
return onActivationEvent();
}
}
}
}
示例7: activate
export function activate(context: vscode.ExtensionContext) : api.PrettifySymbolsMode {
function registerTextEditorCommand(commandId:string, run:(editor:vscode.TextEditor,edit:vscode.TextEditorEdit,...args:any[])=>void): void {
context.subscriptions.push(vscode.commands.registerTextEditorCommand(commandId, run));
}
function registerCommand(commandId:string, run:(...args:any[])=>void): void {
context.subscriptions.push(vscode.commands.registerCommand(commandId, run));
}
registerTextEditorCommand('prettifySymbolsMode.copyWithSubstitutions', copyWithSubstitutions);
registerCommand('prettifySymbolsMode.disablePrettySymbols', disablePrettySymbols);
registerCommand('prettifySymbolsMode.enablePrettySymbols', enablePrettySymbols);
registerCommand('prettifySymbolsMode.togglePrettySymbols', (editor: vscode.TextEditor) => {
if(prettySymbolsEnabled) {
disablePrettySymbols();
} else {
enablePrettySymbols();
}
});
registerCommand('extension.disablePrettySymbols', () => { vscode.window.showErrorMessage('Command "extension.disablePrettySymbols" is deprecated; use "prettifySymbolsMode.disablePrettySymbols" instead.') });
registerCommand('extension.enablePrettySymbols', () => { vscode.window.showErrorMessage('Command "extension.enablePrettySymbols" is deprecated; use "prettifySymbolsMode.enablePrettySymbols" instead.') });
registerCommand('extension.togglePrettySymbols', () => { vscode.window.showErrorMessage('Command "extension.togglePrettySymbols" is deprecated; use "prettifySymbolsMode.togglePrettySymbols" instead.') });
context.subscriptions.push(vscode.window.onDidChangeTextEditorSelection(selectionChanged));
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(openDocument));
context.subscriptions.push(vscode.workspace.onDidCloseTextDocument(closeDocument));
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(onConfigurationChanged));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(changeActiveTextEditor));
reloadConfiguration();
const result : api.PrettifySymbolsMode = {
onDidEnabledChange: function(handler: (enabled:boolean)=>void) : vscode.Disposable {
onEnabledChangeHandlers.add(handler);
return {
dispose() {
onEnabledChangeHandlers.delete(handler);
}
}
},
isEnabled: function() : boolean {
return prettySymbolsEnabled;
},
registerSubstitutions: function(substitutions: api.LanguageEntry) : vscode.Disposable {
additionalSubstitutions.add(substitutions);
// TODO: this could be smart about not unloading & reloading everything
reloadConfiguration();
return {
dispose() {
additionalSubstitutions.delete(substitutions);
}
}
}
};
return result;
}
示例8: activate
export async function activate(context: ExtensionContext) {
const logger = new Logger();
let requestController = new RequestController(context, logger);
let historyController = new HistoryController(logger);
let responseController = new ResponseController();
let codeSnippetController = new CodeSnippetController();
let environmentController = new EnvironmentController(await EnvironmentController.getCurrentEnvironment());
context.subscriptions.push(requestController);
context.subscriptions.push(historyController);
context.subscriptions.push(responseController);
context.subscriptions.push(codeSnippetController);
context.subscriptions.push(environmentController);
context.subscriptions.push(commands.registerCommand('rest-client.request', ((document: TextDocument, range: Range) => requestController.run(range))));
context.subscriptions.push(commands.registerCommand('rest-client.rerun-last-request', () => requestController.rerun()));
context.subscriptions.push(commands.registerCommand('rest-client.cancel-request', () => requestController.cancel()));
context.subscriptions.push(commands.registerCommand('rest-client.history', () => historyController.save()));
context.subscriptions.push(commands.registerCommand('rest-client.clear-history', () => historyController.clear()));
context.subscriptions.push(commands.registerCommand('rest-client.save-response', () => responseController.save()));
context.subscriptions.push(commands.registerCommand('rest-client.save-response-body', () => responseController.saveBody()));
context.subscriptions.push(commands.registerCommand('rest-client.copy-response-body', () => responseController.copyBody()));
context.subscriptions.push(commands.registerCommand('rest-client.generate-codesnippet', () => codeSnippetController.run()));
context.subscriptions.push(commands.registerCommand('rest-client.copy-codesnippet', () => codeSnippetController.copy()));
context.subscriptions.push(commands.registerCommand('rest-client.copy-request-as-curl', () => codeSnippetController.copyAsCurl()));
context.subscriptions.push(commands.registerCommand('rest-client.switch-environment', () => environmentController.switchEnvironment()));
context.subscriptions.push(commands.registerCommand('rest-client.clear-aad-token-cache', () => AadTokenCache.clear()));
context.subscriptions.push(commands.registerCommand('rest-client._openDocumentLink', args => {
workspace.openTextDocument(Uri.parse(args.path)).then(window.showTextDocument, error => {
window.showErrorMessage(error.message);
});
}));
const documentSelector = [
{ language: 'http', scheme: 'file' },
{ language: 'http', scheme: 'untitled' },
];
context.subscriptions.push(languages.registerCompletionItemProvider(documentSelector, new HttpCompletionItemProvider()));
context.subscriptions.push(languages.registerCompletionItemProvider(documentSelector, new RequestVariableCompletionItemProvider(), '.'));
context.subscriptions.push(languages.registerHoverProvider(documentSelector, new CustomVariableHoverProvider()));
context.subscriptions.push(languages.registerHoverProvider(documentSelector, new RequestVariableHoverProvider()));
context.subscriptions.push(
new ConfigurationDependentRegistration(
() => languages.registerCodeLensProvider(documentSelector, new HttpCodeLensProvider()),
s => s.enableSendRequestCodeLens));
context.subscriptions.push(
new ConfigurationDependentRegistration(
() => languages.registerCodeLensProvider(documentSelector, new CustomVariableReferencesCodeLensProvider()),
s => s.enableCustomVariableReferencesCodeLens));
context.subscriptions.push(languages.registerDocumentLinkProvider(documentSelector, new RequestBodyDocumentLinkProvider()));
context.subscriptions.push(languages.registerDefinitionProvider(documentSelector, new CustomVariableDefinitionProvider()));
context.subscriptions.push(languages.registerReferenceProvider(documentSelector, new CustomVariableReferenceProvider()));
context.subscriptions.push(languages.registerDocumentSymbolProvider(documentSelector, new HttpDocumentSymbolProvider()));
const diagnosticsProviders = new VariableDiagnosticsProvider();
workspace.onDidOpenTextDocument(diagnosticsProviders.checkVariables, diagnosticsProviders, context.subscriptions);
workspace.onDidCloseTextDocument(diagnosticsProviders.deleteDocumentFromDiagnosticCollection, diagnosticsProviders, context.subscriptions);
workspace.onDidSaveTextDocument(diagnosticsProviders.checkVariables, diagnosticsProviders, context.subscriptions);
}
示例9: activate
export function activate(context: vscode.ExtensionContext) {
diagnosticCollection = vscode.languages.createDiagnosticCollection('lua');
context.subscriptions.push(diagnosticCollection);
vscode.workspace.onDidSaveTextDocument(document => lintDocument(document, true));
vscode.workspace.onDidChangeTextDocument(event => lintDocument(event.document));
vscode.workspace.onDidOpenTextDocument(document => lintDocument(document));
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => lintDocument(editor.document));
}
示例10: activate
export function activate() {
vscode.workspace.onDidChangeTextDocument((event: TextDocumentChangeEvent) => {
if (!checkUiFlow(event.document)) return;
validateTextDocument(event.document);
});
vscode.workspace.onDidOpenTextDocument(document => {
if (!checkUiFlow(document)) return;
validateTextDocument(document);
});
}