-
Type: Investigation
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
- In VSCODE-23, we're taking the fast path. In the future, let's work out a unified solution for VSCODE, MONGOSH, and COMPASS. Notes/ideas below.
Notes
- All of this lives in something like TypeScript-TmLanguage → MongoDB-TmLanguage and is generated following pattern of https://github.com/microsoft/TypeScript-TmLanguage
VS Code
- https://github.com/microsoft/TypeScript-TmLanguage/blob/master/build/build.ts takes canonical plist
- https://github.com/sheetalkamat/TypeScript-TmLanguage-VsCode/blob/master/build/update-grammar.js for dl master → converting plist into VS Code .json + dependency .json's
Ace Editor
- Add a build task to mongodb-ace-mode to generate https://github.com/mongodb-js/ace-mode/blob/master/index.js using ace/tool/tmlanguage.js
node ace/tool/tmlanguage.js MongoDB.tmLanguage
highlight.js
- https://highlightjs.readthedocs.io/en/latest/language-guide.html is s imilar in simplicity to ace https://cloud9-sdk.readme.io/docs/highlighting-rules
- relevant for mongosh cli and beyond (e.g. leafygreen editor/syntax component, docs, etc.)
mongosh highlighting
Output
repl uses util.inspect() which 1. can be customized 2. replace util.inspect() entirely via the writer option with something like cli-highlight or emphasize
Input
trickier... but possible.
- https://github.com/nikersify/jay "Supercharged JavaScript REPL"
- python impl of similar goal experience https://github.com/laixintao/iredis/
(HT @max for links)
- https://github.com/nikersify/jay/blob/master/source/prompt.ts#L137
- Uses emphasize for highlighting
- Which in turn wraps https://github.com/wooorm/lowlight
- Which wraps highlight.js under the hood :tada:
- mongosh uses node core repl tho
- REPLServer inherits from readline.Interface so running it through emphasize in this fall through of _ttyWrite should do it https://github.com/nodejs/node/blob/master/lib/readline.js#L1058
- two different streams input (passed to eval) and output (whats written to term)
eval() happens input.on('line')|https://github.com/nodejs/node/blob/master/lib/repl.js#L763 which is emitted from input here