VSCode中.html.eex文件需同时支持HTML与HTML(EEx)代码补全求助
.html.eex Files as Both HTML and HTML (EEx) Absolutely, you can get both built-in HTML snippets (like h2+Tab generating <h2></h2>) and your custom HTML (EEx) snippets working together in .html.eex files. Here's a step-by-step solution:
Open your user settings JSON file
PressCtrl+Shift+P(Windows/Linux) orCmd+Shift+P(Mac), typeOpen User Settings (JSON), and hit Enter. This opens the raw JSON config file where we’ll tweak the settings.Add the following configuration
Paste these lines into the JSON file (merge them with any existing settings you have):{ "files.associations": { "*.html.eex": "html-eex" }, "emmet.includeLanguages": { "html-eex": "html" }, "html.validate.enable": true, "[html-eex]": { "editor.quickSuggestions": { "other": true, "comments": false, "strings": true }, "editor.suggest.snippetsPreventQuickSuggestions": false }, "extensions.extendLanguageServices": { "html-eex": "html" } }What each setting does
files.associations: Ensures.html.eexfiles are recognized ashtml-eex(HTML (EEx)) mode, so your custom EEx snippets trigger correctly.emmet.includeLanguages: Tells Emmet (the tool behind those built-in HTML snippets likeh2+Tab) to treathtml-eexfiles as HTML, restoring those built-in shortcuts.html.validate.enable: Turns on HTML syntax checking for your.html.eexfiles, so you get helpful hints about invalid HTML.[html-eex]section: Makes sure quick suggestions (including snippets) pop up reliably without being blocked.extensions.extendLanguageServices: Extends VSCode's HTML language service to work withhtml-eexfiles, so you get full HTML smart features alongside EEx support.
Test it out
Save the settings file, close and re-open your.html.eexfile. Now when you typeh2and press Tab, you should see the built-in<h2>|</h2>snippet appear, and your custom HTML (EEx) snippets should still work as expected.
If you have existing custom snippets, double-check that their scope field includes "html-eex" (e.g., "scope": "html, html-eex"). This ensures they trigger in both HTML and HTML (EEx) contexts.
内容的提问来源于stack exchange,提问作者Peter R

