本文整理汇总了TypeScript中vscode.workspace.onDidChangeTextDocument方法的典型用法代码示例。如果您正苦于以下问题:TypeScript workspace.onDidChangeTextDocument方法的具体用法?TypeScript workspace.onDidChangeTextDocument怎么用?TypeScript workspace.onDidChangeTextDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.workspace
的用法示例。
在下文中一共展示了workspace.onDidChangeTextDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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));
});
示例2: activate
export function activate(context: ExtensionContext): any {
context.subscriptions.push(languages.registerCompletionItemProvider('todo', new TodoCompletionItemProvider(), '@'));
context.subscriptions.push(languages.registerCodeActionsProvider('todo', new TodoCodeActionProvider()));
languages.setLanguageConfiguration('todo', {
wordPattern: /(-?\d*\.\d\w*)|([^\-\`\~\!\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
indentationRules: {
increaseIndentPattern: /^\s*\w+.+:\s*$/,
decreaseIndentPattern: /^\uffff$/ //Does not match any
}
});
let todoCommands= new TodoCommands();
context.subscriptions.push(todoCommands.registerNewTaskCommand());
context.subscriptions.push(todoCommands.registerCompleteTaskCommand());
context.subscriptions.push(todoCommands.registerCancelTaskCommand());
context.subscriptions.push(workspace.onDidChangeTextDocument((e: TextDocumentChangeEvent) => {
_decorateEditor(true);
}));
window.onDidChangeActiveTextEditor(editor => {
_decorateEditor();
}, null, context.subscriptions);
_decorateEditor();
}
示例3: activateTagClosing
export function activateTagClosing(tagProvider: (document: TextDocument, position: Position) => Thenable<string>, supportedLanguages: { [id: string]: boolean }, configName: string): Disposable {
let disposables: Disposable[] = [];
workspace.onDidChangeTextDocument(event => onDidChangeTextDocument(event.document, event.contentChanges), null, disposables);
let isEnabled = false;
updateEnabledState();
window.onDidChangeActiveTextEditor(updateEnabledState, null, disposables);
let timeout: NodeJS.Timer = void 0;
function updateEnabledState() {
isEnabled = false;
let editor = window.activeTextEditor;
if (!editor) {
return;
}
let document = editor.document;
if (!supportedLanguages[document.languageId]) {
return;
}
if (!workspace.getConfiguration(void 0, document.uri).get<boolean>(configName)) {
return;
}
isEnabled = true;
}
function onDidChangeTextDocument(document: TextDocument, changes: TextDocumentContentChangeEvent[]) {
if (!isEnabled) {
return;
}
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
if (document !== activeDocument || changes.length === 0) {
return;
}
if (typeof timeout !== 'undefined') {
clearTimeout(timeout);
}
let lastChange = changes[changes.length - 1];
let lastCharacter = lastChange.text[lastChange.text.length - 1];
if (lastChange.rangeLength > 0 || lastCharacter !== '>' && lastCharacter !== '/') {
return;
}
let rangeStart = lastChange.range.start;
let version = document.version;
timeout = setTimeout(() => {
let position = new Position(rangeStart.line, rangeStart.character + lastChange.text.length);
tagProvider(document, position).then(text => {
if (text && isEnabled) {
let activeDocument = window.activeTextEditor && window.activeTextEditor.document;
if (document === activeDocument && activeDocument.version === version) {
window.activeTextEditor.insertSnippet(new SnippetString(text), position);
}
}
});
}, 100);
}
return Disposable.from(...disposables);
}
示例4: 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;
});
});
}
}));
});
示例5: 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));
}
示例6:
return new Promise<void>((resolve, reject) => {
let subscription = workspace.onDidChangeTextDocument(d => {
if (d.document.uri.toString() === virtualURIString) {
subscription.dispose();
resolve();
}
});
embeddedContentChanged.fire(virtualURI);
});
示例7:
return new Promise<vscode.TextDocument>(resolve => {
const sub = vscode.workspace.onDidChangeTextDocument(e => {
if (e.document !== doc) {
return;
}
sub.dispose();
resolve(e.document);
});
});
示例8: constructor
constructor(private log: Logger) {
this.settings = Settings.load();
if (this.settings.helpCompletion !== Settings.HelpCompletion.Disabled) {
this.helpCompletionProvider = new HelpCompletionProvider();
const subscriptions = [];
workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions);
this.disposable = Disposable.from(...subscriptions);
}
}
示例9: 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);
});
}
示例10: activate
export function activate(context: vscode.ExtensionContext) {
vscode.workspace.onDidChangeTextDocument(event => {
insertAutoCloseTag(event);
});
let closeTag = vscode.commands.registerCommand('auto-close-tag.closeTag', () => {
insertCloseTag();
});
context.subscriptions.push(closeTag);
}