Skip to content

Commit

Permalink
[REFACTOR][VSC] Introduce eslint
Browse files Browse the repository at this point in the history
Introduce eslint and modify code accordingly.
Furthermore gradle has been modified in
order to seperate config and execute statements.
  • Loading branch information
mschaefer88 authored and Michael Schäfer committed Apr 30, 2020
1 parent 0527f70 commit 9e2b21a
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 414 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ task sarosVSCode(type: Copy, dependsOn: [
into 'build/distribution/vscode'
}

task prepareVSCode(dependsOn: [
task buildVSCode(dependsOn: [
'sarosLsp',
'saros.vscode:buildExtension'
]) {
Expand Down
1 change: 1 addition & 0 deletions docs/contribute/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ title: Coding and Commit Guidelines
|---|----------------------------
|`[E]`| This commit ONLY affects the Eclipse version of Saros
|`[I]`| IntelliJ version of Saros
|`[VSC]`| Visual Studio Code version of Saros
|`[S]`| Saros Server
|`[HTML]`| Saros HTML UI
|`[CORE]`| Saros core
Expand Down
32 changes: 32 additions & 0 deletions vscode/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"env": {
"es6": true,
"node": true,
"commonjs": true
},
"extends": [
"eslint:recommended",
"google"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
"project": "tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars-experimental": "error"
},
"root": true
}
62 changes: 26 additions & 36 deletions vscode/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ version = packageJson.version
def vscePath = './node_modules/vsce/out/vsce'

node {
version = '10.14.1'
npmVersion = '6.4.1'
download = true
version = '10.14.1'
npmVersion = '6.4.1'
download = true
}


// npm_run_compile {
// inputs.files fileTree(
// dir: "src",
// excludes: ["bin/**", "node_modules/**"])
// inputs.file 'package.json'
// inputs.file 'package-lock.json'
// inputs.file 'tsconfig.json'
// outputs.dir 'out'
// }

npmInstall {
inputs.files fileTree("./")
inputs.files fileTree(projectDir)
}

task copyLsp(type: Copy) {
from("$rootProject.projectDir/build/distribution/lsp")
into('dist')
doFirst {
from("$rootDir/build/distribution/lsp")
into('dist')
}
}

task buildExtension(dependsOn: [
Expand All @@ -45,16 +36,16 @@ task buildExtension(dependsOn: [
'npm_run_webpack'
]) {
group 'VS Code'
description 'Builds the extension'
description 'Builds the extension'
}

task runExtension(type: Exec, dependsOn: [
'buildExtension'
]) {
group 'VS Code'
description 'Builds and runs the extension'
description 'Builds and runs the extension'

def execArgs = "code --extensionDevelopmentPath=${file('./').absolutePath}"
def execArgs = "code --extensionDevelopmentPath=${projectDir.absolutePath}"

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
executable = 'cmd'
Expand All @@ -64,48 +55,47 @@ task runExtension(type: Exec, dependsOn: [
args = [execArgs]
}

workingDir = file('./out').absolutePath
workingDir = file('./dist').absolutePath
}

task packageExtension(type: NodeTask, dependsOn: [
'copyLsp'
]) {
group 'VS Code'
description 'Packages the extension'
description 'Packages the extension'

delete 'vsix/*'
file('./vsix').mkdirs()
doFirst {
delete 'vsix/*'
file('./vsix').mkdirs()
}

ext.archiveName = "$project.name-${project.version}.vsix"
ext.destPath = "./vsix/$archiveName"
ext.destPath = "./vsix"

script = file(vscePath)
args = ['package', '--out', destPath]
// execOverrides {
// workingDir = file('./')
// }
args = ['package', '--out', destPath]
}

task publishExtension(type: NodeTask, dependsOn: [
'copyLsp'
]) {
group 'VS Code'
description 'Publishes the extension'
description 'Publishes the extension'

script = file(vscePath)
args = ['publish', 'patch']
args = ['publish', 'patch']
execOverrides {
workingDir = file('./')
workingDir = file('./')
}
}

task unpublishExtension(type: NodeTask) {
group 'VS Code'
description 'Unpublishes the extension'
description 'Unpublishes the extension'

script = file(vscePath)
args = ['unpublish', "${packageJson.publisher}.${packageJson.name}"]
args = ['unpublish', "${packageJson.publisher}.${packageJson.name}"]
execOverrides {
workingDir = file('./')
}
workingDir = file('./')
}
}
10 changes: 7 additions & 3 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,25 @@
"webpack-dev": "webpack --mode development --watch",
"test-compile": "tsc -p ./",
"pretest": "npm run compile",
"test": "node ./out/test/runTest.js"
"test": "node ./out/test/runTest.js",
"lint": "eslint */**/*.ts --quiet"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/node": "^10.12.21",
"@types/vscode": "^1.38.0",
"@typescript-eslint/eslint-plugin": "^2.19.2",
"@typescript-eslint/parser": "^2.19.2",
"eslint": "^6.8.0",
"eslint-config-google": "^0.14.0",
"glob": "^7.1.4",
"mocha": "^6.1.4",
"ts-loader": "^6.2.1",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"vsce": "^1.71.0",
"vscode-test": "^1.2.0",
"webpack": "^4.41.5",
"webpack": "^4.41.6",
"webpack-cli": "^3.3.10"
},
"dependencies": {
Expand Down
20 changes: 10 additions & 10 deletions vscode/src/account/activator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SarosExtension } from "../core/saros-extension";
import { commands } from "vscode";
import {commands} from 'vscode';
import {SarosExtension} from '../core';

/**
* Activation function of the account module.
Expand All @@ -8,13 +8,13 @@ import { commands } from "vscode";
* @param {SarosExtension} extension - The instance of the extension
*/
export function activateAccounts(extension: SarosExtension) {
commands.registerCommand('saros.account.add', () => {
extension.onReady()
.then(resolve => {
return extension.client.addAccount('[email protected]');
commands.registerCommand('saros.account.add', () => {
extension.onReady()
.then(() => {
return extension.client.addAccount();
})
.then(r => {
console.log('Response was: ' + r.response);
.then((r) => {
console.log('Response was: ' + r.response);
});
});
}
});
}
1 change: 1 addition & 0 deletions vscode/src/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './activator';
3 changes: 3 additions & 0 deletions vscode/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './saros-lang-client';
export * from './saros-lang-server';
export * from './saros-extension';
93 changes: 44 additions & 49 deletions vscode/src/core/saros-extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ExtensionContext, workspace, window } from "vscode";
import { SarosServer } from "./saros-server";
import { SarosClient } from "./saros-client";
import { LanguageClientOptions, RevealOutputChannelOn } from "vscode-languageclient";
import {workspace, window, ExtensionContext} from 'vscode';
import {SarosLangServer} from './saros-lang-server';
import {SarosLangClient} from './saros-lang-client';
import {LanguageClientOptions,
RevealOutputChannelOn} from 'vscode-languageclient';

/**
* The Saros extension.
Expand All @@ -11,98 +12,92 @@ import { LanguageClientOptions, RevealOutputChannelOn } from "vscode-languagecli
*/
export class SarosExtension {
private context!: ExtensionContext;
public client!: SarosClient;
public client!: SarosLangClient;

/**
* Creates an instance of SarosExtension.
*
* @memberof SarosExtension
*/
constructor() {

}

/**
* Sets the context the extension runs on.
*
* @param {ExtensionContext} context - The extension context
* @returns {SarosExtension} Itself
* @return {SarosExtension} Itself
* @memberof SarosExtension
*/
setContext(context: ExtensionContext): SarosExtension {
this.context = context;
this.context = context;

return this;
return this;
}

/**
* Initializes the extension.
*
* @returns
* @memberof SarosExtension
*/
async init() {

if(!this.context) {
return Promise.reject('Context not set');
}
if (!this.context) {
return Promise.reject(new Error('Context not set'));
}

try {
let self = this;
try {
const self = this;

return new Promise((resolve, reject) => {
const server = new SarosServer(self.context);
self.client = new SarosClient('sarosServer', 'Saros Server', server.getStartFunc(), this.createClientOptions());
self.context.subscriptions.push(self.client.start());
return new Promise((resolve) => {
const server = new SarosLangServer(self.context);
self.client = new SarosLangClient('sarosServer', 'Saros Server',
server.getStartFunc(), this.createClientOptions());
this.context.subscriptions.push(self.client.start());

resolve();
});
} catch(ex) {
const msg = "Error while activating plugin. " + (ex.message ? ex.message : ex);
return Promise.reject(msg);
}
resolve();
});
} catch (ex) {
const msg = 'Error while activating plugin. ' +
(ex.message ? ex.message : ex);
return Promise.reject(new Error(msg));
}
}

/**
* Callback when extension is ready.
*
* @returns
* @memberof SarosExtension
*/
async onReady() {
if(!this.client) {
console.log("onReady.reject");
return Promise.reject('SarosExtension is not initialized');
}
if (!this.client) {
console.log('onReady.reject');
return Promise.reject(new Error('SarosExtension is not initialized'));
}

console.log("onReady");
return this.client.onReady();
console.log('onReady');
return this.client.onReady();
}

/**
* Creates the client options.
*
* @private
* @returns {LanguageClientOptions} The client options
* @return {LanguageClientOptions} The client options
* @memberof SarosExtension
*/
private createClientOptions(): LanguageClientOptions {
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['plaintext'],
synchronize: {
// Synchronize the setting section 'languageServerExample' to the server
//configurationSection: 'sarosServer',
// Notify the server about file changes to '.clientrc files contain in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
},
outputChannel: window.createOutputChannel('Saros'),
revealOutputChannelOn: RevealOutputChannelOn.Info
};
const clientOptions: LanguageClientOptions = {
documentSelector: ['plaintext'],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/.clientrc'),
},
outputChannel: window.createOutputChannel('Saros'),
revealOutputChannelOn: RevealOutputChannelOn.Info,
};

return clientOptions;
return clientOptions;
}
}

export const sarosExtensionInstance = new SarosExtension();
export const sarosExtensionInstance = new SarosExtension();
Loading

0 comments on commit 9e2b21a

Please sign in to comment.