Enforce tab indentation

This commit is contained in:
Pine Wu
2019-03-26 15:53:36 -07:00
parent 28bc263424
commit 8143df9875
2 changed files with 147 additions and 129 deletions

5
.prettierrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"useTabs": true,
"singleQuote": true,
"printWidth": 92
}

View File

@ -8,16 +8,19 @@ const cats = {
};
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('catCoding.start', () => {
context.subscriptions.push(
vscode.commands.registerCommand('catCoding.start', () => {
CatCodingPanel.createOrShow(context.extensionPath);
}));
})
);
context.subscriptions.push(vscode.commands.registerCommand('catCoding.doRefactor', () => {
context.subscriptions.push(
vscode.commands.registerCommand('catCoding.doRefactor', () => {
if (CatCodingPanel.currentPanel) {
CatCodingPanel.currentPanel.doRefactor();
}
}));
})
);
if (vscode.window.registerWebviewPanelSerializer) {
// Make sure we register a serializer in activation event
@ -46,7 +49,9 @@ class CatCodingPanel {
private _disposables: vscode.Disposable[] = [];
public static createOrShow(extensionPath: string) {
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined;
// If we already have a panel, show it.
if (CatCodingPanel.currentPanel) {
@ -55,15 +60,18 @@ class CatCodingPanel {
}
// Otherwise, create a new panel.
const panel = vscode.window.createWebviewPanel(CatCodingPanel.viewType, "Cat Coding", column || vscode.ViewColumn.One, {
const panel = vscode.window.createWebviewPanel(
CatCodingPanel.viewType,
'Cat Coding',
column || vscode.ViewColumn.One,
{
// Enable javascript in the webview
enableScripts: true,
// And restrict the webview to only loading content from our extension's `media` directory.
localResourceRoots: [
vscode.Uri.file(path.join(extensionPath, 'media'))
]
});
localResourceRoots: [vscode.Uri.file(path.join(extensionPath, 'media'))]
}
);
CatCodingPanel.currentPanel = new CatCodingPanel(panel, extensionPath);
}
@ -72,10 +80,7 @@ class CatCodingPanel {
CatCodingPanel.currentPanel = new CatCodingPanel(panel, extensionPath);
}
private constructor(
panel: vscode.WebviewPanel,
extensionPath: string
) {
private constructor(panel: vscode.WebviewPanel, extensionPath: string) {
this._panel = panel;
this._extensionPath = extensionPath;
@ -87,20 +92,28 @@ class CatCodingPanel {
this._panel.onDidDispose(() => this.dispose(), null, this._disposables);
// Update the content based on view changes
this._panel.onDidChangeViewState(e => {
this._panel.onDidChangeViewState(
e => {
if (this._panel.visible) {
this._update()
this._update();
}
}, null, this._disposables);
},
null,
this._disposables
);
// Handle messages from the webview
this._panel.webview.onDidReceiveMessage(message => {
this._panel.webview.onDidReceiveMessage(
message => {
switch (message.command) {
case 'alert':
vscode.window.showErrorMessage(message.text);
return;
}
}, null, this._disposables);
},
null,
this._disposables
);
}
public doRefactor() {
@ -124,7 +137,6 @@ class CatCodingPanel {
}
private _update() {
const z = 1 + 2;
// Vary the webview's content based on where it is located in the editor.
switch (this._panel.viewColumn) {
@ -149,9 +161,10 @@ class CatCodingPanel {
}
private _getHtmlForWebview(catGif: string) {
// Local path to main script run in the webview
const scriptPathOnDisk = vscode.Uri.file(path.join(this._extensionPath, 'media', 'main.js'));
const scriptPathOnDisk = vscode.Uri.file(
path.join(this._extensionPath, 'media', 'main.js')
);
// And the uri we use to load this script in the webview
const scriptUri = scriptPathOnDisk.with({ scheme: 'vscode-resource' });
@ -184,8 +197,8 @@ class CatCodingPanel {
}
function getNonce() {
let text = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}