Skip to content

Commit

Permalink
Support ci lint check (#21)
Browse files Browse the repository at this point in the history
* feat: add lint check

* feat: fix lint error
  • Loading branch information
yubing744 authored Jun 27, 2022
1 parent 0934f43 commit 4844c2c
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 173 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"root": true,
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"node/no-unpublished-import": "off"
"node/no-unpublished-import": "off",
"@typescript-eslint/no-explicit-any": "off"
}
}
15 changes: 14 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ on:
branches: [ 'master', 'release-**' ]
name: Unit Test & Functional Test
jobs:
lint:
name: Lint the code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '14.x'
- name: Install dependencies
run: yarn install
- name: Lint
run: yarn lint
test:
strategy:
fail-fast: false
Expand All @@ -24,4 +37,4 @@ jobs:
with:
run: yarn test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88 changes: 40 additions & 48 deletions src/commands/lsp_commands.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';

import { CommandFactory } from '.';
import { IDEExtensionContext } from '../context';

/**
* startLanguageServer
*/
export const startLanguageServer: CommandFactory = (ctx: IDEExtensionContext) => {
return async (): Promise<void> => {
const logger = ctx.logger

const executable: lc.Executable = {
command: ctx.moveAnalyzerBin || 'move-analyzer',
};
const serverOptions: lc.ServerOptions = {
run: executable,
debug: executable,
};

// The vscode-languageclient module reads a configuration option named
// "<extension-name>.trace.server" to determine whether to log messages. If a trace output
// channel is specified, these messages are printed there, otherwise they appear in the
// output channel that it automatically created by the `LanguageClient` (in this extension,
// that is 'Move Language Server'). For more information, see:
// https://code.visualstudio.com/api/language-extensions/language-server-extension-guide#logging-support-for-language-server
const traceOutputChannel = vscode.window.createOutputChannel(
'Move Analyzer Language Server Trace',
);
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'move' }],
traceOutputChannel,
};

const client = new lc.LanguageClient(
'move-analyzer',
'Move Language Server',
serverOptions,
clientOptions,
);
logger.info('Starting client...');
const disposable = client.start();
ctx.vscode.subscriptions.push(disposable);
ctx.languageClient = client;
};
};
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';

import { CommandFactory } from '.';
import { IDEExtensionContext } from '../context';

/**
* startLanguageServer
*/
export const startLanguageServer: CommandFactory = (ctx: IDEExtensionContext) => {
return async (): Promise<void> => {
const logger = ctx.logger;

const executable: lc.Executable = {
command: ctx.moveAnalyzerBin || 'move-analyzer'
};
const serverOptions: lc.ServerOptions = {
run: executable,
debug: executable
};

// The vscode-languageclient module reads a configuration option named
// "<extension-name>.trace.server" to determine whether to log messages. If a trace output
// channel is specified, these messages are printed there, otherwise they appear in the
// output channel that it automatically created by the `LanguageClient` (in this extension,
// that is 'Move Language Server'). For more information, see:
// https://code.visualstudio.com/api/language-extensions/language-server-extension-guide#logging-support-for-language-server
const traceOutputChannel = vscode.window.createOutputChannel('Move Analyzer Language Server Trace');
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'move' }],
traceOutputChannel
};

const client = new lc.LanguageClient('move-analyzer', 'Move Language Server', serverOptions, clientOptions);
logger.info('Starting client...');
const disposable = client.start();
ctx.vscode.subscriptions.push(disposable);
ctx.languageClient = client;
};
};
6 changes: 3 additions & 3 deletions src/commands/update_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export async function checkAndUpdateWithDownlaoder(
export async function checkAndUpdateMpm(ctx: IDEExtensionContext): Promise<void> {
const loader: Downloader = currentDownloader(ctx.vscode.extensionPath);
await checkAndUpdateWithDownlaoder(ctx.vscode, loader);
ctx.mpmBin = loader.executatePath
ctx.mpmBin = loader.executatePath;
}

export async function checkAndUpdateMoveAnalyzer(ctx: IDEExtensionContext): Promise<void> {
const loader: Downloader = currentAnalyzerDownloader(ctx.vscode.extensionPath);
await checkAndUpdateWithDownlaoder(ctx.vscode, loader);
ctx.moveAnalyzerBin = loader.executatePath
ctx.moveAnalyzerBin = loader.executatePath;
}

/**
Expand All @@ -77,7 +77,7 @@ export async function checkAndUpdateMoveAnalyzer(ctx: IDEExtensionContext): Prom
* @param context
* @returns
*/
export const checkAndUpdateAll: CommandFactory = (ctx: IDEExtensionContext) => {
export const checkAndUpdateAll: CommandFactory = (ctx: IDEExtensionContext) => {
return async (): Promise<void> => {
await checkAndUpdateMpm(ctx);
await checkAndUpdateMoveAnalyzer(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface IDEExtensionContext {

mpmBin?: string;
moveAnalyzerBin?: string;
languageClient?: lc.LanguageClient,
languageClient?: lc.LanguageClient;
}
4 changes: 2 additions & 2 deletions src/download/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function installRelease(
console.log('download timeout');
reject('Network read timeout error');
})
.on('start', (fileSize) => {
.on('start', () => {
if (progressCallback !== null) {
progressCallback(0);
}
Expand All @@ -108,7 +108,7 @@ export async function installRelease(
reject('Network read timeout error');
});
})
.on('end', (output) => {
.on('end', () => {
resolve(null);
})
.on('progress', (progress) => {
Expand Down
54 changes: 27 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ const NAMESPACE = 'starcoin';
const EXTENSION = 'starcoinorg.starcoin-ide';

export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
const ideCtx: IDEExtensionContext = {
namespace: NAMESPACE,
extension: EXTENSION,
vscode: ctx,
logger: new Logger(),
activate,
deactivate,
};

const registerCommand = commands.createRegisterCommand(ideCtx);

registerCommand('starcoin.reloadExtension', commands.reloadExtension);
registerCommand('starcoin.checkAndUpdateAll', commands.checkAndUpdateAll);

await commands.checkAndUpdateAll(ideCtx)();
await commands.startLanguageServer(ideCtx)();

registerCommand('starcoin.build', commands.mpmBuild);
registerCommand('starcoin.testUnit', commands.mpmTestUnit);
registerCommand('starcoin.testIntegration', commands.mpmTestIntegration);
registerCommand('starcoin.testFile', commands.mpmTestFile);
registerCommand('starcoin.publish', commands.mpmPublish);
registerCommand('starcoin.doctor', commands.mpmDoctor);
registerCommand('starcoin.checkCompatibility', commands.mpmCheckCompatibility);
registerCommand('starcoin.release', commands.mpmRelease);
registerCommand('starcoin.clean', commands.mpmClean);
const ideCtx: IDEExtensionContext = {
namespace: NAMESPACE,
extension: EXTENSION,
vscode: ctx,
logger: new Logger(),
activate,
deactivate
};

const registerCommand = commands.createRegisterCommand(ideCtx);

registerCommand('starcoin.reloadExtension', commands.reloadExtension);
registerCommand('starcoin.checkAndUpdateAll', commands.checkAndUpdateAll);

await commands.checkAndUpdateAll(ideCtx)();
await commands.startLanguageServer(ideCtx)();

registerCommand('starcoin.build', commands.mpmBuild);
registerCommand('starcoin.testUnit', commands.mpmTestUnit);
registerCommand('starcoin.testIntegration', commands.mpmTestIntegration);
registerCommand('starcoin.testFile', commands.mpmTestFile);
registerCommand('starcoin.publish', commands.mpmPublish);
registerCommand('starcoin.doctor', commands.mpmDoctor);
registerCommand('starcoin.checkCompatibility', commands.mpmCheckCompatibility);
registerCommand('starcoin.release', commands.mpmRelease);
registerCommand('starcoin.clean', commands.mpmClean);
}

export function deactivate(context: vscode.ExtensionContext): void { }
export function deactivate(): void {}
50 changes: 25 additions & 25 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

import * as vscode from 'vscode';

/**
* A logger for the VS Code extension.
*
* Messages that are logged appear in an output channel created below that is dedicated to the
* extension (or "client"), in the extension user's "Output View." This logger should be used for
* messages related to VS Code and this extension, as opposed to messages regarding the language
* server, which appear in a separate output channel.
**/
export class Logger {
private readonly output = vscode.window.createOutputChannel('Starcoin IDE Output');

/** Log an informational message (as opposed to an error or a warning). */
info(message: string): void {
this.write('INFO', message);
}

private write(label: string, message: string): void {
this.output.appendLine(`${label} [${new Date().toLocaleString()}]: ${message}`);
}
};
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

import * as vscode from 'vscode';

/**
* A logger for the VS Code extension.
*
* Messages that are logged appear in an output channel created below that is dedicated to the
* extension (or "client"), in the extension user's "Output View." This logger should be used for
* messages related to VS Code and this extension, as opposed to messages regarding the language
* server, which appear in a separate output channel.
**/
export class Logger {
private readonly output = vscode.window.createOutputChannel('Starcoin IDE Output');

/** Log an informational message (as opposed to an error or a warning). */
info(message: string): void {
this.write('INFO', message);
}

private write(label: string, message: string): void {
this.output.appendLine(`${label} [${new Date().toLocaleString()}]: ${message}`);
}
}
1 change: 0 additions & 1 deletion test/functional/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as path from 'path';
import { sleep, getTaskResult } from './utils';

suite('Starcoin-IDE.functional.test', () => {

suite('Move commands test', () => {
test('test starcoin build commands', async () => {
const ext = vscode.extensions.getExtension('starcoinorg.starcoin-ide');
Expand Down
Loading

0 comments on commit 4844c2c

Please sign in to comment.