本文整理匯總了TypeScript中vscode.workspace.onDidCloseTextDocument方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript workspace.onDidCloseTextDocument方法的具體用法?TypeScript workspace.onDidCloseTextDocument怎麽用?TypeScript workspace.onDidCloseTextDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.workspace
的用法示例。
在下文中一共展示了workspace.onDidCloseTextDocument方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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();
}));
}
示例2: 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);
}
示例3: loadConfiguration
function loadConfiguration(context: ExtensionContext): void {
const section = workspace.getConfiguration('npm');
if (section) {
validationEnabled = section.get<boolean>('validate.enable', true);
}
diagnosticCollection.clear();
if (validationEnabled) {
workspace.onDidSaveTextDocument(document => {
validateDocument(document);
}, null, context.subscriptions);
window.onDidChangeActiveTextEditor(editor => {
if (editor && editor.document) {
validateDocument(editor.document);
}
}, null, context.subscriptions);
// remove markers on close
workspace.onDidCloseTextDocument(_document => {
diagnosticCollection.clear();
}, null, context.subscriptions);
// workaround for onDidOpenTextDocument
// workspace.onDidOpenTextDocument(document => {
// console.log("onDidOpenTextDocument ", document.fileName);
// validateDocument(document);
// }, null, context.subscriptions);
validateAllDocuments();
}
}
示例4: 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);
};
示例5: handleContentChange
client.onReady().then(() => {
disposable = client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let handleContentChange = (uri: Uri) => {
if (uri.scheme === 'vscode' && uri.authority === 'schemas') {
client.sendNotification(SchemaContentChangeNotification.type, uri.toString());
}
};
toDispose.push(workspace.onDidChangeTextDocument(e => handleContentChange(e.document.uri)));
toDispose.push(workspace.onDidCloseTextDocument(d => handleContentChange(d.uri)));
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
initFoldingProvider();
toDispose.push(workspace.onDidChangeConfiguration(c => {
if (c.affectsConfiguration(foldingSetting)) {
initFoldingProvider();
}
}));
toDispose.push({ dispose: () => foldingProviderRegistration && foldingProviderRegistration.dispose() });
});
示例6: 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);
}
示例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: eventChannel
const chan = eventChannel((emit) => {
vscode.workspace.onDidCloseTextDocument(() => {
if (!vscode.window.activeTextEditor) return;
const doc = vscode.window.activeTextEditor.document;
emit(textContentChanged(doc.uri.fsPath.replace(".git", ""), fs.readFileSync(doc.uri.fsPath.replace(".git", ""), "utf8")))
});
return () => {};
});
示例9: handleContentChange
client.onReady().then(() => {
client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let handleContentChange = (uri: Uri) => {
if (uri.scheme === 'vscode' && uri.authority === 'schemas') {
client.sendNotification(SchemaContentChangeNotification.type, uri.toString());
}
};
toDispose.push(workspace.onDidChangeTextDocument(e => handleContentChange(e.document.uri)));
toDispose.push(workspace.onDidCloseTextDocument(d => handleContentChange(d.uri)));
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
// register color provider
toDispose.push(languages.registerColorProvider(documentSelector, {
provideDocumentColors(document: TextDocument): Thenable<ColorInformation[]> {
let params: DocumentColorParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document)
};
return client.sendRequest(DocumentColorRequest.type, params).then(symbols => {
return symbols.map(symbol => {
let range = client.protocol2CodeConverter.asRange(symbol.range);
let color = new Color(symbol.color.red, symbol.color.green, symbol.color.blue, symbol.color.alpha);
return new ColorInformation(range, color);
});
});
},
provideColorPresentations(color: Color, context): Thenable<ColorPresentation[]> {
let params: ColorPresentationParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(context.document),
color: color,
range: client.code2ProtocolConverter.asRange(context.range)
};
return client.sendRequest(ColorPresentationRequest.type, params).then(presentations => {
return presentations.map(p => {
let presentation = new ColorPresentation(p.label);
presentation.textEdit = p.textEdit && client.protocol2CodeConverter.asTextEdit(p.textEdit);
presentation.additionalTextEdits = p.additionalTextEdits && client.protocol2CodeConverter.asTextEdits(p.additionalTextEdits);
return presentation;
});
});
}
}));
});
示例10: Promise
const p = new Promise((resolve, reject) => {
const sub = workspace.onDidCloseTextDocument(doc => {
try {
sub.dispose();
assert.ok(window.activeTextEditor === undefined);
assert.equal(window.visibleTextEditors.length, 0);
resolve();
} catch (e) {
reject(e);
}
});
});