Commit bc59ed70 authored by Jérome Perrin's avatar Jérome Perrin

Initial commit

parents
Make completion provider from https://github.com/joe-re/sql-language-server
directly available to monaco editor.
// minimal "do nothing" log4js
export class Logger {
new(dispatch: Function, name: string) {
return this;
}
level: string = "";
log(...args: any[]): void {
console.log(args);
}
isLevelEnabled(level?: string): boolean {
return false;
}
isTraceEnabled(): boolean {
return false;
}
isDebugEnabled(): boolean {
return false;
}
isInfoEnabled(): boolean {
return false;
}
isWarnEnabled(): boolean {
return false;
}
isErrorEnabled(): boolean {
return false;
}
isFatalEnabled(): boolean {
return false;
}
_log(level: string, data: any) {}
addContext(key: string, value: any) {}
removeContext(key: string) {}
clearContext() {}
trace(message: any, ...args: any[]) {
console.trace(args);
}
debug(message: any, ...args: any[]) {
console.debug(args);
}
info(message: any, ...args: any[]) {
console.info(args);
}
warn(message: any, ...args: any[]) {
console.warn(args);
}
error(message: any, ...args: any[]) {
console.error(args);
}
fatal(message: any, ...args: any[]) {
console.error(args);
}
}
export function getLogger(category?: string): Logger {
return new Logger();
}
export function configure() {}
export function addLayout() {}
export function connectLogger() {}
export function shutdown() {}
import complete from "sql-language-server/complete";
import * as monaco from "monaco-editor-core";
import { Schema } from "sql-language-server/database_libs/AbstractClient";
// Pos from sql-language-server
type SQLLanguageServerPos = { line: number; column: number };
export class SQLCompletionProvider
implements monaco.languages.CompletionItemProvider {
private schema: Schema;
public triggerCharacters = [",", ".", " "];
constructor(schema: Schema) {
this.schema = schema;
}
fromMonacoPosition(position: monaco.Position): SQLLanguageServerPos {
return {
line: position.lineNumber - 1,
column: position.column - 1
};
}
public provideCompletionItems(
model: monaco.editor.ITextModel,
position: monaco.Position,
context: monaco.languages.CompletionContext,
token: monaco.CancellationToken
): monaco.languages.ProviderResult<monaco.languages.CompletionList> {
const completionsFromSQLLanguageServer = complete(
model.getValue(),
this.fromMonacoPosition(position),
this.schema
);
const completions: monaco.languages.CompletionList = {
suggestions: []
};
completionsFromSQLLanguageServer.candidates.forEach(comp => {
let monacoCompletion: monaco.languages.CompletionItem = {
label: comp.label,
kind: comp.kind,
insertText: comp.insertText || comp.label,
range: null,
documentation: comp.detail ? comp.detail.replace(/^column/, "") : ""
};
completions.suggestions.push(monacoCompletion);
});
return completions;
}
}
This diff is collapsed.
{
"name": "monaco-editor-sql-completion-provider",
"scripts": {
"build": "tsc && webpack --config webpack.config.js"
},
"dependencies": {
"monaco-editor-core": "^0.18.1",
"sql-language-server": "0.0.2"
},
"devDependencies": {
"source-map-loader": "^0.2.4",
"terser-webpack-plugin": "^2.3.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-merge": "^4.2.2"
}
}
{
"compilerOptions": {
"noImplicitAny": false,
"target": "es6",
"module": "none",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"stripInternal": true,
"outDir": "build"
},
"include": [".", "node_modules/sql-language-server/"]
}
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const TerserPlugin = require("terser-webpack-plugin");
const common = {
entry: {
"monaco-editor-sql-completion-provider": path.resolve(
__dirname,
"build",
"index.js"
)
},
output: {
filename: "[name].bundle.js",
// library: "SQLCompletionProvider",
libraryTarget: "umd"
},
target: "web",
node: {
fs: "empty",
child_process: "empty",
net: "empty",
crypto: "empty",
vscode: "empty"
},
resolve: {
alias: {
log4js: require.resolve("./build/dummy_log4js.js")
}
}
};
if (process.env["NODE_ENV"] === "production") {
module.exports = merge(common, {
mode: "production",
plugins: [
new TerserPlugin({
parallel: true,
terserOptions: {
ecma: 6
}
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
})
]
});
} else {
module.exports = merge(common, {
mode: "development",
devtool: "source-map",
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
loader: "source-map-loader"
}
]
}
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment