@senx/discovery-code
Version:
Discovery Code Editor
56 lines (55 loc) • 2.12 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 { Range } from "monaco-editor";
export class W10HoverProvider {
constructor(languageId) {
this.languageId = languageId;
}
// noinspection JSUnusedLocalSymbols
_provideHover(model, position, _token, provider) {
const word = model.getWordAtPosition(position);
if (!!word) {
const range = new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
const name = word.word;
const entry = provider[name];
if (entry && entry.description) {
const signature = (entry.signature || '').split('\n').map(s => '+ ' + s).join('\n');
const contents = [
{ value: '### ' + name },
{ value: signature },
{ value: entry.description.replace(/(\/doc\/\w+)/g, x => `https://www.warp10.io${x}`) }
];
return { range, contents: W10HoverProvider.toMarkedStringArray(contents) };
}
}
return undefined;
}
static toMarkedStringArray(contents) {
if (!contents) {
return void 0;
}
if (Array.isArray(contents)) {
return contents.map(W10HoverProvider.toMarkdownString);
}
return [W10HoverProvider.toMarkdownString(contents)];
}
static toMarkdownString(entry) {
if (typeof entry === 'string') {
return { value: entry };
}
return { value: entry.value };
}
}