Skip to content

Commit

Permalink
feat: remove lstypes about because it is for node-lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
HaydenOrz authored and wewoor committed Jun 12, 2023
1 parent 3c82a16 commit 3b5c06e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 218 deletions.
9 changes: 5 additions & 4 deletions src/baseSQLWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export abstract class BaseSQLWorker {
if (this.keywords.length === 0) {
const lexer = this.parser.createLexer('');
this.keywords =
// @ts-ignore
lexer.vocabulary.symbolicNames
.filter((keyword: string) => !!keyword)
.map((k: string) => {
Expand Down Expand Up @@ -51,12 +52,12 @@ export abstract class BaseSQLWorker {
if (code) {
// TODO: going to do server side search in future, but now just get all keywords for completion
const keywords: string[] = this.getKeywords();
return Promise.resolve({
items: keywords.map((i) => ({
return Promise.resolve(
keywords.map((i) => ({
label: i,
kind: 14
kind: 17
}))
});
);
}
return Promise.resolve();
}
Expand Down
148 changes: 5 additions & 143 deletions src/languageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
Range,
languages,
Position,
CancellationToken,
IRange
CancellationToken
} from './fillers/monaco-editor-core';
import { debounce } from './common/utils';

import * as lsTypes from './lsTypes';

export interface WorkerAccessor<T> {
(first: Uri, ...more: Uri[]): Promise<T>;
}
Expand All @@ -25,7 +22,7 @@ export interface IWorker extends ILanguageWorkerWithCompletions {
}

export interface ILanguageWorkerWithCompletions {
doComplete(uri: string, position: lsTypes.Position): Promise<lsTypes.CompletionList | null>;
doComplete(uri: string, position: Position): Promise<languages.CompletionItem[] | null>;
}

export class DiagnosticsAdapter<T extends IWorker> {
Expand Down Expand Up @@ -150,10 +147,7 @@ export class CompletionAdapter<T extends IWorker> implements languages.Completio

return this._worker(resource)
.then((worker) => {
return worker.doComplete(
editor.getModel(resource)?.getValue() || '',
fromPosition(position)
);
return worker.doComplete(editor.getModel(resource)?.getValue() || '', position);
})
.then((info) => {
console.log('info:', info);
Expand All @@ -168,33 +162,13 @@ export class CompletionAdapter<T extends IWorker> implements languages.Completio
wordInfo.endColumn
);

const items: languages.CompletionItem[] = info.items.map((entry) => {
const items: languages.CompletionItem[] = info.map((entry: any) => {
const item: languages.CompletionItem = {
label: entry.label,
insertText: entry.insertText || entry.label,
range: wordRange,
kind: toCompletionItemKind(entry.kind)
kind: entry.kind
};
if (entry.textEdit) {
if (isInsertReplaceEdit(entry.textEdit)) {
item.range = {
insert: toRange(entry.textEdit.insert),
replace: toRange(entry.textEdit.replace)
};
} else {
item.range = toRange(entry.textEdit.range);
}
item.insertText = entry.textEdit.newText;
}
if (entry.additionalTextEdits) {
item.additionalTextEdits = (
entry.additionalTextEdits as any[]
).map<languages.TextEdit>(toTextEdit);
}
if (entry.insertTextFormat === lsTypes.InsertTextFormat.Snippet) {
item.insertTextRules =
languages.CompletionItemInsertTextRule.InsertAsSnippet;
}
return item;
});

Expand All @@ -204,115 +178,3 @@ export class CompletionAdapter<T extends IWorker> implements languages.Completio
});
}
}

export function fromPosition(position: Position): lsTypes.Position;
export function fromPosition(position: undefined): undefined;
export function fromPosition(position: Position | undefined): lsTypes.Position | undefined;
export function fromPosition(position: Position | undefined): lsTypes.Position | undefined {
if (!position) {
return void 0;
}
return { character: position.column - 1, line: position.lineNumber - 1 };
}

export function fromRange(range: IRange): lsTypes.Range;
export function fromRange(range: undefined): undefined;
export function fromRange(range: IRange | undefined): lsTypes.Range | undefined;
export function fromRange(range: IRange | undefined): lsTypes.Range | undefined {
if (!range) {
return void 0;
}
return {
start: {
line: range.startLineNumber - 1,
character: range.startColumn - 1
},
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
};
}
export function toRange(range: lsTypes.Range): Range;
export function toRange(range: undefined): undefined;
export function toRange(range: lsTypes.Range | undefined): Range | undefined;
export function toRange(range: lsTypes.Range | undefined): Range | undefined {
if (!range) {
return void 0;
}
return new Range(
range.start.line + 1,
range.start.character + 1,
range.end.line + 1,
range.end.character + 1
);
}

function isInsertReplaceEdit(
edit: lsTypes.TextEdit | lsTypes.InsertReplaceEdit
): edit is lsTypes.InsertReplaceEdit {
return (
typeof (<lsTypes.InsertReplaceEdit>edit).insert !== 'undefined' &&
typeof (<lsTypes.InsertReplaceEdit>edit).replace !== 'undefined'
);
}

function toCompletionItemKind(kind: number | undefined): languages.CompletionItemKind {
const mItemKind = languages.CompletionItemKind;

switch (kind) {
case lsTypes.CompletionItemKind.Text:
return mItemKind.Text;
case lsTypes.CompletionItemKind.Method:
return mItemKind.Method;
case lsTypes.CompletionItemKind.Function:
return mItemKind.Function;
case lsTypes.CompletionItemKind.Constructor:
return mItemKind.Constructor;
case lsTypes.CompletionItemKind.Field:
return mItemKind.Field;
case lsTypes.CompletionItemKind.Variable:
return mItemKind.Variable;
case lsTypes.CompletionItemKind.Class:
return mItemKind.Class;
case lsTypes.CompletionItemKind.Interface:
return mItemKind.Interface;
case lsTypes.CompletionItemKind.Module:
return mItemKind.Module;
case lsTypes.CompletionItemKind.Property:
return mItemKind.Property;
case lsTypes.CompletionItemKind.Unit:
return mItemKind.Unit;
case lsTypes.CompletionItemKind.Value:
return mItemKind.Value;
case lsTypes.CompletionItemKind.Enum:
return mItemKind.Enum;
case lsTypes.CompletionItemKind.Keyword:
return mItemKind.Keyword;
case lsTypes.CompletionItemKind.Snippet:
return mItemKind.Snippet;
case lsTypes.CompletionItemKind.Color:
return mItemKind.Color;
case lsTypes.CompletionItemKind.File:
return mItemKind.File;
case lsTypes.CompletionItemKind.Reference:
return mItemKind.Reference;
}
return mItemKind.Property;
}

export function toTextEdit(textEdit: lsTypes.TextEdit): languages.TextEdit;
export function toTextEdit(textEdit: undefined): undefined;
export function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined;
export function toTextEdit(textEdit: lsTypes.TextEdit | undefined): languages.TextEdit | undefined {
if (!textEdit) {
return void 0;
}
return {
range: toRange(textEdit.range),
text: textEdit.newText
};
}

function toCommand(c: lsTypes.Command | undefined): languages.Command | undefined {
return c && c.command === 'editor.action.triggerSuggest'
? { id: c.command, title: c.title, arguments: c.arguments }
: undefined;
}
71 changes: 0 additions & 71 deletions src/lsTypes.ts

This file was deleted.

0 comments on commit 3b5c06e

Please sign in to comment.