Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Make generated file edit warning optional (#1537)
Browse files Browse the repository at this point in the history
* Make generated file edit warning optional

* Lint fix

* Change flag to globalState
  • Loading branch information
lggomez authored and ramya-rao-a committed Mar 4, 2018
1 parent 71d675a commit c2fa007
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { goBuild } from './goBuild';

let statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
statusBarItem.command = 'go.test.showOutput';
const neverAgain = { title: 'Don\'t Show Again' };

export function removeTestStatus(e: vscode.TextDocumentChangeEvent) {
if (e.document.isUntitled) {
Expand All @@ -29,12 +30,20 @@ export function removeTestStatus(e: vscode.TextDocumentChangeEvent) {
}

export function notifyIfGeneratedFile(e: vscode.TextDocumentChangeEvent) {
let ctx = this;
if (e.document.isUntitled || e.document.languageId !== 'go') {
return;
}

if (e.document.lineAt(0).text.match(/^\/\/ Code generated .* DO NOT EDIT\.$/)) {
vscode.window.showWarningMessage('This file seems to be generated. DO NOT EDIT.');
let documentUri = e ? e.document.uri : null;
let goConfig = vscode.workspace.getConfiguration('go', documentUri);

if ((ctx.globalState.get('ignoreGeneratedCodeWarning') !== true) && e.document.lineAt(0).text.match(/^\/\/ Code generated .* DO NOT EDIT\.$/)) {
vscode.window.showWarningMessage('This file seems to be generated. DO NOT EDIT.', neverAgain).then(result => {
if (result === neverAgain) {
ctx.globalState.update('ignoreGeneratedCodeWarning', true);
}
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function activate(ctx: vscode.ExtensionContext): void {
vscode.window.onDidChangeActiveTextEditor(showHideStatus, null, ctx.subscriptions);
vscode.window.onDidChangeActiveTextEditor(getCodeCoverage, null, ctx.subscriptions);
vscode.workspace.onDidChangeTextDocument(parseLiveFile, null, ctx.subscriptions);
vscode.workspace.onDidChangeTextDocument(notifyIfGeneratedFile, null, ctx.subscriptions);
vscode.workspace.onDidChangeTextDocument(notifyIfGeneratedFile, ctx, ctx.subscriptions);

startBuildOnSaveWatcher(ctx.subscriptions);

Expand Down

0 comments on commit c2fa007

Please # to comment.