@senx/discovery-code
Version:
Discovery Code Editor
79 lines (78 loc) • 2.88 kB
JavaScript
/*
* Copyright 2020 SenX S.A.S.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { languages } from "monaco-editor";
var CompletionItemKind = languages.CompletionItemKind;
export class W10CompletionItemProvider {
constructor(languageId, config) {
this.languageId = languageId;
this.config = config;
}
_provideCompletionItems(_model, _position, _context, _token, source, snippets) {
const defs = {
suggestions: [],
};
source.forEach(f => {
const item = {
label: this.transformKeyWord(f.name),
insertText: this.transformKeyWord(f.name),
range: undefined,
kind: W10CompletionItemProvider.getType(f.tags, f.name)
};
defs.suggestions.push(item);
});
Object.keys(snippets).forEach(s => {
const snippet = snippets[s];
defs.suggestions.push({
label: snippet.prefix,
kind: languages.CompletionItemKind.Snippet,
insertTextRules: languages.CompletionItemInsertTextRule.InsertAsSnippet,
documentation: snippet.prefix,
insertText: snippet.body.join('\n')
});
});
return Promise.resolve(defs);
}
static getType(tags, name) {
const t = tags.join(' ');
if (t.indexOf('constant') > -1) {
return CompletionItemKind.Enum;
}
else if (t.indexOf('reducer') > -1 && name !== 'REDUCE') {
return CompletionItemKind.Interface;
}
else if (t.indexOf('mapper') > -1 && name !== 'MAP') {
return CompletionItemKind.Interface;
}
else if (t.indexOf('bucketize') > -1 && name !== 'BUCKETIZE') {
return CompletionItemKind.Interface;
}
else if (t.indexOf('filter') > -1 && name !== 'FILTER') {
return CompletionItemKind.Interface;
}
else if (t.indexOf('control') > -1) {
return CompletionItemKind.Keyword;
}
else if (t.indexOf('operators') > -1) {
return CompletionItemKind.Method;
}
else if (t.indexOf('stack') > -1) {
return CompletionItemKind.Module;
}
else {
return CompletionItemKind.Function;
}
}
}