當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript workspace.onDidChangeTextDocument方法代碼示例

本文整理匯總了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));
	});
開發者ID:developers23,項目名稱:vscode,代碼行數:27,代碼來源:jsonMain.ts

示例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();
}
開發者ID:AmreeshTyagi,項目名稱:vscode-todotasks,代碼行數:27,代碼來源:TodoExtensionMain.ts

示例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);
}
開發者ID:pavelfeldman,項目名稱:vscode,代碼行數:59,代碼來源:tagClosing.ts

示例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;
					});
				});
			}
		}));
	});
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:58,代碼來源:jsonMain.ts

示例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));
}
開發者ID:karai17,項目名稱:vscode-lualinter,代碼行數:9,代碼來源:extension.ts

示例6:

			return new Promise<void>((resolve, reject) => {
				let subscription = workspace.onDidChangeTextDocument(d => {
					if (d.document.uri.toString() === virtualURIString) {
						subscription.dispose();
						resolve();
					}
				});
				embeddedContentChanged.fire(virtualURI);
			});
開發者ID:elemongw,項目名稱:vscode,代碼行數:9,代碼來源:embeddedContentDocuments.ts

示例7:

	return new Promise<vscode.TextDocument>(resolve => {
		const sub = vscode.workspace.onDidChangeTextDocument(e => {
			if (e.document !== doc) {
				return;
			}
			sub.dispose();
			resolve(e.document);
		});
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:9,代碼來源:onEnter.test.ts

示例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);
        }
    }
開發者ID:dfinke,項目名稱:vscode-powershell,代碼行數:10,代碼來源:HelpCompletion.ts

示例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);
	});
}
開發者ID:kexi,項目名稱:vscode-uiflow,代碼行數:10,代碼來源:diagnostic.ts

示例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);
}
開發者ID:formulahendry,項目名稱:vscode-auto-close-tag,代碼行數:11,代碼來源:extension.ts


注:本文中的vscode.workspace.onDidChangeTextDocument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。