style: prettier

This commit is contained in:
iCrawl 2019-09-22 18:56:19 +02:00
parent c74e5c7bab
commit ff75ecf2c5
No known key found for this signature in database
GPG key ID: E41A6DB922EC2CFE
7 changed files with 167 additions and 64 deletions

View file

@ -20,7 +20,8 @@
"scripts": { "scripts": {
"prebuild": "yarn lint", "prebuild": "yarn lint",
"build": "webpack --mode production", "build": "webpack --mode production",
"lint": "eslint src --ext .ts" "lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix"
}, },
"activationEvents": [ "activationEvents": [
"*" "*"
@ -196,6 +197,9 @@
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"eslint": "^6.4.0", "eslint": "^6.4.0",
"eslint-config-marine": "^5.0.0", "eslint-config-marine": "^5.0.0",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-prettier": "^3.1.1",
"prettier": "^1.18.2",
"terser-webpack-plugin": "^2.1.0", "terser-webpack-plugin": "^2.1.0",
"ts-loader": "^6.1.2", "ts-loader": "^6.1.2",
"typescript": "^3.6.3", "typescript": "^3.6.3",
@ -206,6 +210,6 @@
"vscode": "^1.38.0" "vscode": "^1.38.0"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "marine/node" "extends": "marine/prettier/node"
} }
} }

View file

@ -30,6 +30,7 @@ export default class RPCClient implements Disposable {
public async setActivity(workspaceElapsedTime = false) { public async setActivity(workspaceElapsedTime = false) {
if (!this._rpc) return; if (!this._rpc) return;
const activity = await this._activity.generate(workspaceElapsedTime); const activity = await this._activity.generate(workspaceElapsedTime);
if (!activity) return;
Logger.log('Sending activity to Discord.'); Logger.log('Sending activity to Discord.');
this._rpc.setActivity(activity); this._rpc.setActivity(activity);
} }
@ -70,7 +71,7 @@ export default class RPCClient implements Disposable {
this.statusBarIcon.tooltip = 'Connected to Discord'; this.statusBarIcon.tooltip = 'Connected to Discord';
// @ts-ignore // @ts-ignore
setTimeout(() => this.statusBarIcon.text = '$(globe)', 5000); setTimeout(() => (this.statusBarIcon.text = '$(globe)'), 5000);
if (activityTimer) clearInterval(activityTimer); if (activityTimer) clearInterval(activityTimer);
await this.setActivity(); await this.setActivity();
@ -101,13 +102,18 @@ export default class RPCClient implements Disposable {
// Same here, this is a real nasty race condition that happens inside the discord-rpc module currently // Same here, this is a real nasty race condition that happens inside the discord-rpc module currently
// To circumvent this we need to timeout sending the subscribe events to the discord client // To circumvent this we need to timeout sending the subscribe events to the discord client
setTimeout(() => { setTimeout(() => {
this._rpc.subscribe('ACTIVITY_JOIN_REQUEST', async ({ user }: { user: { username: string; discriminator: string } }) => this._rpc.subscribe(
window.showInformationMessage(`${user.username}#${user.discriminator} wants to join your session`, { title: 'Accept' }, { title: 'Decline' }) 'ACTIVITY_JOIN_REQUEST',
// eslint-disable-next-line async ({ user }: { user: { username: string; discriminator: string } }) => {
.then(async (val: { title: string } | undefined) => { const val = await window.showInformationMessage(
if (val && val.title === 'Accept') await this._rpc.sendJoinInvite(user); // eslint-disable-line `${user.username}#${user.discriminator} wants to join your session`,
else await this._rpc.closeJoinRequest(user); { title: 'Accept' },
})); { title: 'Decline' },
);
if (val && val.title === 'Accept') await this._rpc.sendJoinInvite(user);
else await this._rpc.closeJoinRequest(user);
},
);
}, 1000); }, 1000);
setTimeout(() => { setTimeout(() => {
this._rpc.subscribe('ACTIVITY_JOIN', async ({ secret }: { secret: string }) => { this._rpc.subscribe('ACTIVITY_JOIN', async ({ secret }: { secret: string }) => {

View file

@ -4,5 +4,5 @@ export const VSLS_EXTENSION_ID = 'ms-vsliveshare.vsliveshare';
export const LIVE_SHARE_COMMANDS = { export const LIVE_SHARE_COMMANDS = {
START: 'liveshare.start', START: 'liveshare.start',
END: 'liveshare.end', END: 'liveshare.end',
JOIN: 'liveshare.join' JOIN: 'liveshare.join',
}; };

View file

@ -96,7 +96,16 @@ export async function activate(context: ExtensionContext) {
await rpc.disableJoinRequests(); await rpc.disableJoinRequests();
}); });
context.subscriptions.push(enabler, disabler, reconnecter, disconnect, allowSpectate, disableSpectate, allowJoinRequests, disableJoinRequests); context.subscriptions.push(
enabler,
disabler,
reconnecter,
disconnect,
allowSpectate,
disableSpectate,
allowJoinRequests,
disableJoinRequests,
);
} }
export async function deactivate() { export async function deactivate() {

View file

@ -48,23 +48,43 @@ export default class Activity implements Disposable {
let largeImageKey: any = 'vscode-big'; let largeImageKey: any = 'vscode-big';
if (window.activeTextEditor) { if (window.activeTextEditor) {
if (window.activeTextEditor.document.languageId === 'Log') return this._state; if (window.activeTextEditor.document.languageId === 'Log') return this._state;
if (window.activeTextEditor.document.fileName === this._lastKnownFile) { if (this._state && window.activeTextEditor.document.fileName === this._lastKnownFile) {
return this._state = { return (this._state = {
...this._state, ...this._state,
details: await this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', this._state!.largeImageKey), details: await this._generateDetails(
smallImageKey: debug.activeDebugSession ? 'debug' : env.appName.includes('Insiders') ? 'vscode-insiders' : 'vscode', 'detailsDebugging',
state: await this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', this._state!.largeImageKey) 'detailsEditing',
}; 'detailsIdle',
this._state.largeImageKey,
),
smallImageKey: debug.activeDebugSession
? 'debug'
: env.appName.includes('Insiders')
? 'vscode-insiders'
: 'vscode',
state: await this._generateDetails(
'lowerDetailsDebugging',
'lowerDetailsEditing',
'lowerDetailsIdle',
this._state.largeImageKey,
),
});
} }
this._lastKnownFile = window.activeTextEditor.document.fileName; this._lastKnownFile = window.activeTextEditor.document.fileName;
const filename = basename(window.activeTextEditor.document.fileName); const filename = basename(window.activeTextEditor.document.fileName);
largeImageKey = knownExtentions[Object.keys(knownExtentions).find(key => { largeImageKey =
if (filename.endsWith(key)) return true; knownExtentions[
const match = key.match(/^\/(.*)\/([mgiy]+)$/); Object.keys(knownExtentions).find(key => {
if (!match) return false; if (filename.endsWith(key)) return true;
const regex = new RegExp(match[1], match[2]); const match = /^\/(.*)\/([mgiy]+)$/.exec(key);
return regex.test(filename); if (!match) return false;
})!] || (knownLanguages.includes(window.activeTextEditor.document.languageId) ? window.activeTextEditor.document.languageId : null); const regex = new RegExp(match[1], match[2]);
return regex.test(filename);
})!
] ||
(knownLanguages.includes(window.activeTextEditor.document.languageId)
? window.activeTextEditor.document.languageId
: null);
} }
let previousTimestamp = null; let previousTimestamp = null;
@ -73,18 +93,38 @@ export default class Activity implements Disposable {
this._state = { this._state = {
...this._state, ...this._state,
details: await this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', largeImageKey), details: await this._generateDetails('detailsDebugging', 'detailsEditing', 'detailsIdle', largeImageKey),
startTimestamp: window.activeTextEditor && previousTimestamp && workspaceElapsedTime ? previousTimestamp : window.activeTextEditor ? new Date().getTime() : null, startTimestamp:
state: await this._generateDetails('lowerDetailsDebugging', 'lowerDetailsEditing', 'lowerDetailsIdle', largeImageKey), window.activeTextEditor && previousTimestamp && workspaceElapsedTime
? previousTimestamp
: window.activeTextEditor
? new Date().getTime()
: null,
state: await this._generateDetails(
'lowerDetailsDebugging',
'lowerDetailsEditing',
'lowerDetailsIdle',
largeImageKey,
),
largeImageKey: largeImageKey ? largeImageKey.image || largeImageKey : 'txt', largeImageKey: largeImageKey ? largeImageKey.image || largeImageKey : 'txt',
largeImageText: window.activeTextEditor largeImageText: window.activeTextEditor
? this._config.get<string>('largeImage')! ? this._config
.replace('{lang}', largeImageKey ? largeImageKey.image || largeImageKey : 'txt') .get<string>('largeImage')!
.replace('{Lang}', largeImageKey ? (largeImageKey.image || largeImageKey).toLowerCase().replace(/^\w/, (c: string) => c.toUpperCase()) : 'Txt') .replace('{lang}', largeImageKey ? largeImageKey.image || largeImageKey : 'txt')
.replace('{LANG}', largeImageKey ? (largeImageKey.image || largeImageKey).toUpperCase() : 'TXT') || .replace(
window.activeTextEditor.document.languageId.padEnd(2, '\u200b') '{Lang}',
largeImageKey
? (largeImageKey.image || largeImageKey).toLowerCase().replace(/^\w/, (c: string) => c.toUpperCase())
: 'Txt',
)
.replace('{LANG}', largeImageKey ? (largeImageKey.image || largeImageKey).toUpperCase() : 'TXT') ||
window.activeTextEditor.document.languageId.padEnd(2, '\u200b')
: this._config.get<string>('largeImageIdle'), : this._config.get<string>('largeImageIdle'),
smallImageKey: debug.activeDebugSession ? 'debug' : env.appName.includes('Insiders') ? 'vscode-insiders' : 'vscode', smallImageKey: debug.activeDebugSession
smallImageText: this._config.get<string>('smallImage')!.replace('{appname}', env.appName) ? 'debug'
: env.appName.includes('Insiders')
? 'vscode-insiders'
: 'vscode',
smallImageText: this._config.get<string>('smallImage')!.replace('{appname}', env.appName),
}; };
return this._state; return this._state;
@ -98,7 +138,7 @@ export default class Activity implements Disposable {
this._state = { this._state = {
...this._state, ...this._state,
spectateSecret: join ? Buffer.from(join.toString()).toString('base64') : undefined, spectateSecret: join ? Buffer.from(join.toString()).toString('base64') : undefined,
instance: true instance: true,
}; };
return this._state; return this._state;
@ -127,7 +167,7 @@ export default class Activity implements Disposable {
partySize: 1, partySize: 1,
partyMax: 5, partyMax: 5,
joinSecret: join ? Buffer.from(join.toString()).toString('base64') : undefined, joinSecret: join ? Buffer.from(join.toString()).toString('base64') : undefined,
instance: true instance: true,
}; };
return this._state; return this._state;
@ -163,7 +203,7 @@ export default class Activity implements Disposable {
partyId: id, partyId: id,
partySize: this._state.partySize ? this._state.partySize + 1 : 1, partySize: this._state.partySize ? this._state.partySize + 1 : 1,
partyMax: 5, partyMax: 5,
instance: true instance: true,
}; };
return this._state; return this._state;
@ -174,7 +214,7 @@ export default class Activity implements Disposable {
if (this.state && this._state.partySize === 5) return; if (this.state && this._state.partySize === 5) return;
this._state = { this._state = {
...this._state, ...this._state,
partySize: this._state.partySize ? this._state.partySize + 1 : size partySize: this._state.partySize ? this._state.partySize + 1 : size,
}; };
return this._state; return this._state;
@ -185,7 +225,7 @@ export default class Activity implements Disposable {
if (this.state && this._state.partySize === 1) return; if (this.state && this._state.partySize === 1) return;
this._state = { this._state = {
...this._state, ...this._state,
partySize: this._state.partySize ? this._state.partySize - 1 : size partySize: this._state.partySize ? this._state.partySize - 1 : size,
}; };
return this._state; return this._state;
@ -228,19 +268,29 @@ export default class Activity implements Disposable {
} }
const { totalLines, size, currentLine, currentColumn } = await this._generateFileDetails(raw); const { totalLines, size, currentLine, currentColumn } = await this._generateFileDetails(raw);
raw = raw! raw = raw
.replace('{null}', empty) .replace('{null}', empty)
.replace('{filename}', filename) .replace('{filename}', filename)
.replace('{dirname}', dirname) .replace('{dirname}', dirname)
.replace('{fulldirname}', fullDirname!) .replace('{fulldirname}', fullDirname!)
.replace('{workspace}', checkState && workspaceFolder ? workspaceFolder.name : this._config.get<string>('lowerDetailsNotFound')!.replace('{null}', empty)) .replace(
'{workspace}',
checkState && workspaceFolder
? workspaceFolder.name
: this._config.get<string>('lowerDetailsNotFound')!.replace('{null}', empty),
)
.replace('{lang}', largeImageKey ? largeImageKey.image || largeImageKey : 'txt') .replace('{lang}', largeImageKey ? largeImageKey.image || largeImageKey : 'txt')
.replace('{Lang}', largeImageKey ? (largeImageKey.image || largeImageKey).toLowerCase().replace(/^\w/, (c: string) => c.toUpperCase()) : 'Txt') .replace(
'{Lang}',
largeImageKey
? (largeImageKey.image || largeImageKey).toLowerCase().replace(/^\w/, (c: string) => c.toUpperCase())
: 'Txt',
)
.replace('{LANG}', largeImageKey ? (largeImageKey.image || largeImageKey).toUpperCase() : 'TXT'); .replace('{LANG}', largeImageKey ? (largeImageKey.image || largeImageKey).toUpperCase() : 'TXT');
if (totalLines) raw = raw!.replace('{totallines}', totalLines); if (totalLines) raw = raw.replace('{totallines}', totalLines);
if (size) raw = raw!.replace('{filesize}', size); if (size) raw = raw.replace('{filesize}', size);
if (currentLine) raw = raw!.replace('{currentline}', currentLine); if (currentLine) raw = raw.replace('{currentline}', currentLine);
if (currentColumn) raw = raw!.replace('{currentcolumn}', currentColumn); if (currentColumn) raw = raw.replace('{currentcolumn}', currentColumn);
} }
return raw; return raw;

View file

@ -1,5 +1,3 @@
'use strict';
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin'); const TerserPlugin = require('terser-webpack-plugin');
@ -8,18 +6,16 @@ module.exports = {
entry: './src/extension.ts', entry: './src/extension.ts',
output: { output: {
filename: 'extension.js', filename: 'extension.js',
libraryTarget: 'commonjs2' libraryTarget: 'commonjs2',
}, },
devtool: 'source-map', devtool: 'source-map',
externals: { externals: {
vscode: 'commonjs vscode' vscode: 'commonjs vscode',
}, },
resolve: { resolve: {
extensions: ['.ts', '.js', '.json'] extensions: ['.ts', '.js', '.json'],
}, },
plugins: [ plugins: [new CleanWebpackPlugin()],
new CleanWebpackPlugin()
],
optimization: { optimization: {
minimizer: [ minimizer: [
new TerserPlugin({ new TerserPlugin({
@ -30,16 +26,18 @@ module.exports = {
ecma: 8, ecma: 8,
mangle: false, mangle: false,
keep_classnames: true, keep_classnames: true,
keep_fnames: true keep_fnames: true,
} },
}) }),
] ],
}, },
module: { module: {
rules: [{ rules: [
test: /\.ts$/, {
use: 'ts-loader', test: /\.ts$/,
exclude: /node_modules/ use: 'ts-loader',
}] exclude: /node_modules/,
} },
],
},
}; };

View file

@ -1156,6 +1156,20 @@ eslint-config-marine@^5.0.0:
eslint-config-aqua "^7.0.1" eslint-config-aqua "^7.0.1"
eslint-plugin-promise "^4.2.1" eslint-plugin-promise "^4.2.1"
eslint-config-prettier@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.3.0.tgz#e73b48e59dc49d950843f3eb96d519e2248286a3"
integrity sha512-EWaGjlDAZRzVFveh2Jsglcere2KK5CJBhkNSa1xs3KfMUGdRiT7lG089eqPdvlzWHpAqaekubOsOMu8W8Yk71A==
dependencies:
get-stdin "^6.0.0"
eslint-plugin-prettier@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.1.tgz#507b8562410d02a03f0ddc949c616f877852f2ba"
integrity sha512-A+TZuHZ0KU0cnn56/9mfR7/KjUJ9QNVXUhwvRFSR7PGPe0zQR6PTkmyqg1AtUUEOzTqeRsUwyKFh0oVZKVCrtA==
dependencies:
prettier-linter-helpers "^1.0.0"
eslint-plugin-promise@^4.2.1: eslint-plugin-promise@^4.2.1:
version "4.2.1" version "4.2.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz#845fd8b2260ad8f82564c1222fce44ad71d9418a" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz#845fd8b2260ad8f82564c1222fce44ad71d9418a"
@ -1359,6 +1373,11 @@ fast-deep-equal@^2.0.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk= integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-diff@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
fast-json-stable-stringify@^2.0.0: fast-json-stable-stringify@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@ -1549,6 +1568,11 @@ get-caller-file@^2.0.1:
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
get-stdin@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b"
integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==
get-stream@^4.0.0: get-stream@^4.0.0:
version "4.1.0" version "4.1.0"
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5"
@ -2792,6 +2816,18 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
prettier-linter-helpers@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
dependencies:
fast-diff "^1.1.2"
prettier@^1.18.2:
version "1.18.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"
integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==
process-nextick-args@~2.0.0: process-nextick-args@~2.0.0:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"