简体   繁体   English

使用 addExtraLib 向 Monaco 编辑器添加自定义受限 Javascript 自动完成集

[英]Adding custom limited Javascript autocomplete set to Monaco editor with addExtraLib

I would like to limit the amount of suggestions Monaco gives me on default with plain Javascript.我想限制摩纳哥在默认情况下使用纯 Javascript 给我的建议数量。 Things like autocompleting array object's properties such as length are welcome but anything related to DOM or CSS elements is not needed.自动完成数组对象的属性(例如长度)之类的东西是受欢迎的,但不需要任何与 DOM 或 CSS 元素相关的东西。

There's a Github issue reply that describes how this can be achieved in theory, but there's an issue ran into with the approach described in the link.有一个 Github 问题回复描述理论上如何实现这一点,但是链接中描述的方法存在问题。 The custom definitions for JS such as lib.es5.d.ts are so long that if I try to convert the whole definition to Javascript string and feed to Monaco through monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri); JS 的自定义定义(例如lib.es5.d.ts)太长了,如果我尝试将整个定义转换为 Javascript 字符串并通过monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);提供给 Monaco monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri); function, Javascript crashes to RangeError: Maximum call stack size exceeded because the string containing the definitions is too long to process.函数,Javascript 崩溃至RangeError: Maximum call stack size exceeded因为包含定义的字符串太长而无法处理。

Is there a way to configure Monaco so that only lib.es5.d.ts definitions are being used with autocomplete, or perhaps some way around the too long string issue?有没有办法配置摩纳哥,以便只有 lib.es5.d.ts 定义与自动完成一起使用,或者可能以某种方式解决过长的字符串问题?

This was solved by using a webpack raw-loader to import the definitions as a js handle and then passing that handle to monaco.languages.typescript.javascriptDefaults.setExtraLibs(...) function appropriately.这是通过使用 webpack raw-loader 将定义导入为 js 句柄,然后将该句柄适当地传递给monaco.languages.typescript.javascriptDefaults.setExtraLibs(...)函数来解决的。 Many different definitions can be included this way.可以通过这种方式包含许多不同的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM