CodeMirror Markdown Sample has autocomplete for JS but not for Python

Hi! I’m new to CodeMirror, and I’m trying to make autocompletion from an LSP work with Markdown codeblocks.

Right now, I’m planning to create an autocompletion source by getting the Fenced Code node at the current cursor position and getting it’s child CodeInfo to get the language mode, and base the completion list from that.

However, I noticed that in the code block highlighting example, the JS block has a working autocompletion, but if I insert a python code block, highlighting works but autocompletion does not. Granted, the docs mention that the codeLanguages property is used as basis of syntax highlighting and not autocompletion, but was still wondering if it’s possible to configure autocompletion on non-javascript code blocks based on codeLanguages?


Dynamically loaded languages will not have their ‘support’ extensions enabled in the editor. Because the Markdown mode directly uses the HTML mode (for HTML tags) and that one directly includes the JS extensions (for <script> tags), those are part of the editor’s initial configuration, but the ones for Python are not. If you arrange for python().support to be included in (or dynamically added to) your configuration, you’ll get autocompletion in Python snippets.

1 Like

I see, thank you, I got it working!

Although I do have a related question, I’m thinking if I should use compartments instead of pushing the language support to the markdown language because linting and tooltips will also be based on the language of the fenced code. Do linting and tooltips have a version of{autocomplete: source})? Or would it be better to just reconfigure the editor extension based on what fenced code the cursor is in?

Linting is global, done on the outer document. I’m not sure what you mean by ‘tooltips’.

Got it, looks like compartments would be the way to go for linting. Thanks a lot!