本文整理匯總了TypeScript中vscode.workspace.onWillSaveTextDocument方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript workspace.onWillSaveTextDocument方法的具體用法?TypeScript workspace.onWillSaveTextDocument怎麽用?TypeScript workspace.onWillSaveTextDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vscode.workspace
的用法示例。
在下文中一共展示了workspace.onWillSaveTextDocument方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor() {
const subscriptions: Disposable[] = [];
window.onDidChangeActiveTextEditor(Display.updateEditor, this, subscriptions);
var config = workspace.getConfiguration('perforce');
if(config && PerforceCommands.checkFolderOpened()) {
if(config['editOnFileSave']) {
workspace.onWillSaveTextDocument(e => {
e.waitUntil(this.onWillSaveFile(e.document));
}, this, subscriptions);
}
if(config['editOnFileModified']) {
workspace.onDidChangeTextDocument(this.onFileModified, this, subscriptions);
}
if(config['addOnFileCreate'] || config['deleteOnFileDelete']) {
this._watcher = workspace.createFileSystemWatcher('**/*', false, true, false);
if(config['addOnFileCreate']) {
this._watcher.onDidCreate(this.onFileCreated, this, subscriptions);
}
if(config['deleteOnFileDelete']) {
this._watcher.onDidDelete(this.onFileDeleted, this, subscriptions);
}
}
}
this._disposable = Disposable.from.apply(this, subscriptions);
}
示例2: activateFormatOnSaveProvider
export function activateFormatOnSaveProvider(languageFilter: vscode.DocumentFilter, settings: settings.IPythonSettings, outputChannel: vscode.OutputChannel, workspaceRootPath?: string): vscode.Disposable {
let formatters = new Map<string, BaseFormatter>();
let pythonSettings = settings;
let yapfFormatter = new YapfFormatter(outputChannel, settings, workspaceRootPath);
let autoPep8 = new AutoPep8Formatter(outputChannel, settings, workspaceRootPath);
formatters.set(yapfFormatter.Id, yapfFormatter);
formatters.set(autoPep8.Id, autoPep8);
return vscode.workspace.onWillSaveTextDocument(e => {
const document = e.document;
if (document.languageId !== languageFilter.language) {
return;
}
let textEditor = vscode.window.activeTextEditor;
let editorConfig = vscode.workspace.getConfiguration('editor');
const globalEditorFormatOnSave = editorConfig && editorConfig.has('formatOnSave') && editorConfig.get('formatOnSave') === true;
if ((pythonSettings.formatting.formatOnSave || globalEditorFormatOnSave) && textEditor.document === document) {
let formatter = formatters.get(pythonSettings.formatting.provider);
telemetryHelper.sendTelemetryEvent(telemetryContracts.IDE.Format, { Format_Provider: formatter.Id, Format_OnSave: "true" });
e.waitUntil(formatter.formatDocument(document, null, null));
}
}, null, null);
}
示例3: configurationChanged
function configurationChanged() {
let config = workspace.getConfiguration('tslint');
let autoFix = config.get('autoFixOnSave', false);
if (autoFix && !willSaveTextDocument) {
willSaveTextDocument = workspace.onWillSaveTextDocument((event) => {
let document = event.document;
// only auto fix when the document was not auto saved
if (!isTypeScriptDocument(document.languageId) || event.reason === TextDocumentSaveReason.AfterDelay) {
return;
}
const version = document.version;
event.waitUntil(
client.sendRequest(AllFixesRequest.type, { textDocument: { uri: document.uri.toString() } }).then((result) => {
if (result && version === result.documentVersion) {
return Protocol2Code.asTextEdits(result.edits);
} else {
return [];
}
})
);
});
} else if (!autoFix && willSaveTextDocument) {
willSaveTextDocument.dispose();
willSaveTextDocument = undefined;
}
}
示例4: activate
export function activate(context: vscode.ExtensionContext) {
const formatter = new TidyFormatter();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(formatter.readSettings, formatter));
context.subscriptions.push(vscode.workspace.onWillSaveTextDocument(formatter.formatAuto, formatter));
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(HTMLFilter, formatter));
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider(HTMLFilter, formatter));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.tidyHtml', formatter.formatTextEditor, formatter));
return formatter;
}
示例5: registerEventListeners
private registerEventListeners(): void {
let disposables: vscode.Disposable[] = []
if (this.settings.liveMatching) {
disposables.push(
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor | undefined) => {
if (editor !== undefined) {
this.logger.log(`onDidChangeActiveTextEditor event called - ${editor.document.fileName}`);
this.trailingSpaces.highlight(editor);
}
}),
vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
if (vscode.window.activeTextEditor !== undefined && vscode.window.activeTextEditor.document == event.document) {
this.logger.log(`onDidChangeTextDocument event called - ${event.document.fileName}`);
this.trailingSpaces.highlight(vscode.window.activeTextEditor);
}
}),
vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => {
if (vscode.window.activeTextEditor !== undefined && vscode.window.activeTextEditor.document == document) {
this.logger.log(`onDidOpenTextDocument event called - ${document.fileName}`);
this.trailingSpaces.highlight(vscode.window.activeTextEditor);
}
})
);
if (!this.settings.highlightCurrentLine) {
disposables.push(
vscode.window.onDidChangeTextEditorSelection((event: vscode.TextEditorSelectionChangeEvent) => {
let editor: vscode.TextEditor = event.textEditor;
this.logger.log(`onDidChangeTextEditorSelection event called - ${editor.document.fileName}`);
this.trailingSpaces.highlight(editor);
})
);
}
}
if (this.settings.trimOnSave) {
disposables.push(
vscode.workspace.onWillSaveTextDocument((event: vscode.TextDocumentWillSaveEvent) => {
this.logger.log(`onWillSaveTextDocument event called - ${event.document.fileName}`);
vscode.window.visibleTextEditors.forEach((editor: vscode.TextEditor) => {
if (event.document.uri === editor.document.uri) {
event.waitUntil(Promise.resolve(this.trailingSpaces.getEditsForDeletingTralingSpaces(editor.document)));
}
});
})
);
}
this.listenerDisposables = disposables;
}
示例6: constructor
constructor() {
const subscriptions: Disposable[] = [];
// Listen for changes in the active text editor
subscriptions.push(window.onDidChangeActiveTextEditor(textEditor => {
if (textEditor && textEditor.document) {
this._onDidOpenDocument(textEditor.document);
}
}));
// Listen for changes in the configuration
subscriptions.push(workspace.onDidChangeConfiguration(
this._onConfigChanged.bind(this)
));
// Listen for saves to ".editorconfig" files and rebuild the map
subscriptions.push(workspace.onDidSaveTextDocument(savedDocument => {
if (path.basename(savedDocument.fileName) === '.editorconfig') {
// Saved an .editorconfig file => rebuild map entirely and then
// apply the changes to the .editorconfig file itself
this._rebuildConfigMap();
// TODO The transformations should be applied to the `.editorconfig` file as well after the config
// has been rebuilt
// this._rebuildConfigMap().then(applyOnSaveTransformations.bind(
// undefined,
// savedDocument,
// this
// ));
return;
}
}));
subscriptions.push(workspace.onWillSaveTextDocument(e => {
const edits = calculatePreSaveTransformations(e.document, this);
e.waitUntil(Promise.resolve(edits));
}));
// dispose event subscriptons upon disposal
this._disposable = Disposable.from.apply(this, subscriptions);
// Build the map (cover the case that documents were opened before
// my activation)
this._rebuildConfigMap();
// Load the initial workspace configuration
this._onConfigChanged();
}
示例7: formatFile
export const maybeActivateFormatOnSave = () => {
vscode.workspace.onWillSaveTextDocument(e => {
const document = e.document;
if (document.languageId !== "clojure") {
return;
}
let textEditor = vscode.window.activeTextEditor;
if (!textEditor) {
return
}
let editorConfig = vscode.workspace.getConfiguration('editor');
const globalEditorFormatOnSave = editorConfig && editorConfig.has('formatOnSave') && editorConfig.get('formatOnSave') === true;
let clojureConfig = vscode.workspace.getConfiguration('clojureVSCode');
if ((clojureConfig.formatOnSave || globalEditorFormatOnSave) && textEditor.document === document) {
formatFile(textEditor, undefined);
}
});
}
示例8: activate
export function activate(context: vscode.ExtensionContext) {
var docType: Array<string> = ['css', 'scss', 'javascript', 'html', 'json'];
for (var i = 0, l = docType.length; i < l; i++) {
registerDocType(docType[i]);
}
let formatter = new Formatter();
context.subscriptions.push(vscode.commands.registerCommand('Lonefy.formatting', () => {
formatter.beautify();
}));
context.subscriptions.push(vscode.commands.registerCommand('Lonefy.formatterConfig', () => {
formatter.openConfig(
path.join(getRootPath(), '.vscode', 'formatter.json'),
function () {
showMesage('[Local] After editing the file, remember to Restart VScode');
},
function () {
var fileName = path.join(__dirname, 'formatter.json');
formatter.openConfig(
fileName,
function () {
showMesage('[Golbal] After editing the file, remember to Restart VScode');
},
function () {
showMesage('Not found file: ' + fileName);
})
})
}));
context.subscriptions.push(vscode.commands.registerCommand('Lonefy.formatterCreateLocalConfig', () => {
formatter.generateLocalConfig();
}));
context.subscriptions.push(vscode.workspace.onWillSaveTextDocument(e => {
formatter.onSave(e)
}));
function registerDocType(type) {
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(type, {
provideDocumentFormattingEdits: (document, options, token) => {
return formatter.registerBeautify(null)
}
}));
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider(type, {
provideDocumentRangeFormattingEdits: (document, range, options, token) => {
var start = new vscode.Position(0, 0);
var end = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);
return formatter.registerBeautify(new vscode.Range(start, end))
}
}));
}
}
示例9: activate
export function activate(context: ExtensionContext) {
extensionContext = context
outputChannel = vscode.window.createOutputChannel("Dotty");
const sbtArtifact = "org.scala-sbt:sbt-launch:1.2.3"
const buildSbtFile = `${vscode.workspace.rootPath}/build.sbt`
const dottyPluginSbtFile = path.join(extensionContext.extensionPath, './out/dotty-plugin.sbt')
const disableDottyIDEFile = `${vscode.workspace.rootPath}/.dotty-ide-disabled`
const languageServerArtifactFile = `${vscode.workspace.rootPath}/.dotty-ide-artifact`
const languageServerDefaultConfigFile = path.join(extensionContext.extensionPath, './out/default-dotty-ide-config')
const coursierPath = path.join(extensionContext.extensionPath, './out/coursier');
vscode.workspace.onWillSaveTextDocument(worksheet.prepareWorksheet)
vscode.workspace.onDidSaveTextDocument(document => {
if (worksheet.isWorksheet(document)) {
worksheet.evaluateWorksheet(document)
}
})
vscode.workspace.onDidCloseTextDocument(document => {
if (worksheet.isWorksheet(document)) {
worksheet.removeWorksheet(document)
}
})
if (process.env['DLS_DEV_MODE']) {
const portFile = `${vscode.workspace.rootPath}/.dotty-ide-dev-port`
fs.readFile(portFile, (err, port) => {
if (err) {
outputChannel.appendLine(`Unable to parse ${portFile}`)
throw err
}
run({
module: context.asAbsolutePath('out/src/passthrough-server.js'),
args: [ port.toString() ]
}, false)
})
} else {
// Check whether `.dotty-ide-artifact` exists. If it does, start the language server,
// otherwise, try propose to start it if there's no build.sbt
if (fs.existsSync(languageServerArtifactFile)) {
runLanguageServer(coursierPath, languageServerArtifactFile)
} else if (!fs.existsSync(disableDottyIDEFile) && !fs.existsSync(buildSbtFile)) {
vscode.window.showInformationMessage(
"This looks like an unconfigured Scala project. Would you like to start the Dotty IDE?",
"Yes", "No"
).then(choice => {
if (choice == "Yes") {
fs.readFile(languageServerDefaultConfigFile, (err, data) => {
if (err) throw err
else {
const languageServerScalaVersion = data.toString().trim()
fetchAndConfigure(coursierPath, sbtArtifact, languageServerScalaVersion, dottyPluginSbtFile).then(() => {
runLanguageServer(coursierPath, languageServerArtifactFile)
})
}
})
} else {
fs.appendFile(disableDottyIDEFile, "", _ => {})
}
})
}
}
}