基于 monaco 编辑器的命名空间自动完成 [英] monaco editor based namespace auto complete

查看:67
本文介绍了基于 monaco 编辑器的命名空间自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 monaco 编辑器可以根据您的自定义规则自动完成提示.但我不知道如何自动完成基于命名空间;

I know monaco editor can auto complete hints according to your custom rules.But I don't know how to auto complete based namespace;

像这样:

推荐答案

// Add additonal d.ts files to the JavaScript language service and change.
// Also change the default compilation options.
// The sample below shows how a class Facts is declared and introduced
// to the system and how the compiler is told to use ES6 (target=2).

// validation settings
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
    noSemanticValidation: true,
    noSyntaxValidation: false
});

// compiler options
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
    target: monaco.languages.typescript.ScriptTarget.ES6,
    allowNonTsExtensions: true
});

// extra libraries
monaco.languages.typescript.javascriptDefaults.addExtraLib([
    'namespace test{',
    '/** custom variable',
    ' *',
    ' */',
    'declare interface custom {',
    '/** id html */',
    'id :string;',
    '};',
    '',
    '/** this function does something strange ...',
    ' * @param i my custom variable',
    ' */',
    'declare function MyCustomFunction(i :custom) :void;',
    '}'
].join('\n'), 'filename/facts.d.ts');

var jsCode = [
    ''
].join('\n');

monaco.editor.create(document.getElementById("container"), {
    value: jsCode,
    language: "javascript"
});

https://jsfiddle.net/hec12da1/62/

这篇关于基于 monaco 编辑器的命名空间自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆