Skip to content

Commit 9ef1cb1

Browse files
authored
Refactor (#121)
* split identifier from complete.ts * move some functions to utils * define error types on parser * fix the logics getting location from error * remove unused function * remove any type from complete.ts * move getColumnRefByPos to utils * move makeColumnName to utils * move createTablesFromFromNodes to utils * move findColumnAtPosition to utils * move getAllNestedFromNodes to utils * integrate prettier * add import rules * remove semi column and force to use single quote * build before lint
1 parent 07e7f0b commit 9ef1cb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2768
-1595
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ migrations/
1010
webpack.config.js
1111
*/monaco_editor/models/
1212
*/monaco_editor/config/config.js
13+
*/monaco_editor/src/client/client.ts
14+
*/monaco_editor/src/server/server.ts
1315
.eslintrc.js

.eslintrc.js

+41-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,54 @@ module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
44
plugins: [
5+
'import',
56
'@typescript-eslint',
67
],
8+
settings: {
9+
node: {
10+
tryExtensions: ['.ts', '.js'],
11+
},
12+
},
713
extends: [
814
'eslint:recommended',
915
'plugin:@typescript-eslint/recommended',
16+
'plugin:prettier/recommended',
17+
'prettier',
18+
'plugin:node/recommended',
1019
],
1120
rules: {
1221
"@typescript-eslint/no-non-null-assertion": 0,
13-
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
22+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
23+
'node/no-unsupported-features/es-syntax': 'off',
24+
'node/no-extraneous-import': 'off',
25+
"node/no-missing-import": ["error", {
26+
"allowModules": ["vscode"]
27+
}],
28+
'import/first': 0,
29+
'import/named': 2,
30+
'import/namespace': 2,
31+
'import/default': 2,
32+
'import/export': 2,
33+
'import/order': [
34+
'error',
35+
{
36+
groups: [
37+
'builtin',
38+
'external',
39+
'internal',
40+
'parent',
41+
'sibling',
42+
'index',
43+
],
44+
pathGroups: [
45+
{
46+
pattern: '@classdo/**',
47+
group: 'internal',
48+
},
49+
],
50+
pathGroupsExcludedImportTypes: [],
51+
'newlines-between': 'never',
52+
},
53+
],
1454
}
1555
};

.github/workflows/test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
env:
1515
PYTHON_VERSION: 3.8.12
1616
- run: yarn install
17+
- run: yarn npm:prepublish
1718
- run: yarn lint
1819
- run: yarn vsc-compile:client
1920
- run: yarn vsc-compile:server

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ packages/server/dist/*
1515
!.yarn/versions
1616
.pnp.*
1717
.node-version
18+
yarn-error.log

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

example/monaco_editor/src/client/client.ts

+30-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as monaco from 'monaco-editor-core';
2-
import { listen } from '@codingame/monaco-jsonrpc';
1+
import * as monaco from "monaco-editor-core";
2+
import { listen } from "@codingame/monaco-jsonrpc";
33
import {
44
MonacoLanguageClient,
55
MonacoServices,
@@ -8,11 +8,11 @@ import {
88
MessageConnection,
99
} from "monaco-languageclient";
1010
import ReconnectingWebSocket from "reconnecting-websocket";
11-
import { URI } from 'vscode-uri'
11+
import { URI } from "vscode-uri";
1212

1313
let languageClient: MonacoLanguageClient;
14-
let connectionNames: string[] = []
15-
let connectedConnectionName = ''
14+
let connectionNames: string[] = [];
15+
let connectedConnectionName = "";
1616

1717
export function initClient() {
1818
monaco.languages.register({
@@ -44,14 +44,16 @@ export function initClient() {
4444
const disposable = languageClient.start();
4545
connection.onClose(() => disposable.dispose());
4646
languageClient.onReady().then(() => {
47-
languageClient.onNotification('sqlLanguageServer.finishSetup', (params) => {
48-
connectionNames =
49-
params.personalConfig?.connections?.
50-
map((v: { name: string}) => v.name).
51-
filter((v: string) => !!v)
52-
connectedConnectionName = params.config?.name || ''
53-
})
54-
})
47+
languageClient.onNotification(
48+
"sqlLanguageServer.finishSetup",
49+
(params) => {
50+
connectionNames = params.personalConfig?.connections
51+
?.map((v: { name: string }) => v.name)
52+
.filter((v: string) => !!v);
53+
connectedConnectionName = params.config?.name || "";
54+
}
55+
);
56+
});
5557
},
5658
});
5759

@@ -63,10 +65,10 @@ export function initClient() {
6365
clientOptions: {
6466
documentSelector: ["sql"],
6567
workspaceFolder: {
66-
uri: URI.file('/opt/sql-language-server/example/monaco_editor'),
67-
name: 'workspace',
68-
index: 0
69-
}
68+
uri: URI.file("/opt/sql-language-server/example/monaco_editor"),
69+
name: "workspace",
70+
index: 0,
71+
},
7072
},
7173
connectionProvider: {
7274
get: (errorHandler, closeHandler) => {
@@ -97,18 +99,18 @@ export function getLanguageClient() {
9799

98100
export function executeFixAllFixableProblemsCommand() {
99101
const params: ExecuteCommandParams = {
100-
command: 'fixAllFixableProblems',
101-
arguments: ['inmemory://model.sql']
102-
}
103-
languageClient.sendRequest('workspace/executeCommand', params)
102+
command: "fixAllFixableProblems",
103+
arguments: ["inmemory://model.sql"],
104+
};
105+
languageClient.sendRequest("workspace/executeCommand", params);
104106
}
105107

106108
export function executeSwitchDatabaseCommand(db: string) {
107109
const params: ExecuteCommandParams = {
108-
command: 'switchDatabaseConnection',
109-
arguments: [db]
110-
}
111-
languageClient.sendRequest('workspace/executeCommand', params)
110+
command: "switchDatabaseConnection",
111+
arguments: [db],
112+
};
113+
languageClient.sendRequest("workspace/executeCommand", params);
112114
}
113115

114116
export function executeWorkspaceConfig(_db: string) {
@@ -120,9 +122,9 @@ export function executeWorkspaceConfig(_db: string) {
120122
}
121123

122124
export function getConnectionList() {
123-
return connectionNames
125+
return connectionNames;
124126
}
125127

126128
export function getCurrecntConnection() {
127-
return connectedConnectionName
128-
}
129+
return connectedConnectionName;
130+
}
+5-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import App from './App.svelte'
33
import { initClient } from './client'
4-
5-
(self as any).MonacoEnvironment = {
6-
getWorkerUrl: () => './editor.worker.bundle.js'
4+
;(self as any).MonacoEnvironment = {
5+
getWorkerUrl: () => './editor.worker.bundle.js',
76
}
87

98
const app = new App({
109
target: document.body,
11-
});
10+
})
1211

13-
(window as any).app = app;
12+
;(window as any).app = app
1413

1514
initClient()
1615

17-
// export default app;
16+
// export default app;
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
require('./client');
1+
require('./client')

example/monaco_editor/src/server/launchServer.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import * as rpc from "@codingame/monaco-jsonrpc";
2-
import { createConnection } from 'vscode-languageserver/node';
1+
import * as rpc from '@codingame/monaco-jsonrpc'
2+
import { createConnection } from 'vscode-languageserver/node'
33
import { createServerWithConnection } from 'sql-language-server/src/createServer'
44

55
export function launchServer(socket: rpc.IWebSocket) {
6-
const reader = new rpc.WebSocketMessageReader(socket);
7-
const writer = new rpc.WebSocketMessageWriter(socket);
6+
const reader = new rpc.WebSocketMessageReader(socket)
7+
const writer = new rpc.WebSocketMessageWriter(socket)
88
const asExternalProccess =
9-
process.argv.findIndex((value) => value === "--external") !== -1;
9+
process.argv.findIndex((value) => value === '--external') !== -1
1010
if (asExternalProccess) {
1111
// start the language server as an external process
1212
// TODO: implement it
13-
1413
// const extJsonServerPath = path.resolve(__dirname, "ext-json-server.js");
1514
// const socketConnection = server.createConnection(reader, writer, () =>
1615
// socket.dispose()

example/monaco_editor/src/server/server.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ process.on("uncaughtException", function (err: any) {
1414
}
1515
});
1616

17-
let server: http.Server
18-
17+
let server: http.Server;
18+
1919
function startServer() {
2020
const app = express();
2121
app.use(express.static(`${process.cwd()}/dist`));
2222
server = app.listen(3000);
23-
console.log('startServer')
23+
console.log("startServer");
2424

2525
const wss = new ws.Server({
2626
noServer: true,
2727
perMessageDeflate: false,
2828
});
29-
29+
3030
server.on(
3131
"upgrade",
3232
(request: http.IncomingMessage, socket: net.Socket, head: Buffer) => {
@@ -60,4 +60,4 @@ function startServer() {
6060
);
6161
}
6262

63-
startServer()
63+
startServer();

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@
9797
"@typescript-eslint/eslint-plugin": "^5.10.1",
9898
"@typescript-eslint/parser": "^5.10.1",
9999
"eslint": "^8.8.0",
100+
"eslint-config-prettier": "^8.3.0",
101+
"eslint-plugin-import": "^2.25.4",
102+
"eslint-plugin-node": "^11.1.0",
103+
"eslint-plugin-prettier": "^4.0.0",
100104
"lerna": "^4.0.0",
101105
"npm-run-all": "^4.1.5",
106+
"prettier": "^2.5.1",
102107
"typescript": "^4.5.5",
103108
"wait-on": "^5.0.1"
104109
},

0 commit comments

Comments
 (0)