-
Notifications
You must be signed in to change notification settings - Fork 28.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[html] support imports in embedded JavaScript #114115
Comments
(Experimental duplicate detection) |
There's currently no plan to add cross-file support for HTML editing. #47331 is the main issue |
The principle of JSDoc is to document JavaScript code and help developers in the IDE. It doesn't matter where the JavaScript is located. Not supporting import in HTML files is a HUGE ISSUE. The HTML file is the originator of the JavaScript. Please plan to add this functionality, or let me contact the person who has it in its power and I may be able to change your priorities. |
|
is that still true? if it is - I assume it's because it's hard to support... anyone got any hints why it's hard? I feels like it could "just" be a virtual js file (at the same file location) and then let the "normal" JS completion "handle it". but yeah that doesn't work... I tried with but even for the "simplest case" 👉 export const foo = { on: 'foo', off: 'baz' } 👉 <script type="module">
import { foo } from './foo.js';
foo.o // no autocomplete for on/off
</script> it won't follow imports 🙈 here is the relevant code for the request forwarding... am I doing something wrong? (I hope I do - or is it not supposed to work) workspace.registerTextDocumentContentProvider('embedded-content', {
provideTextDocumentContent: uri => {
const originalUri = uri.path.slice(1).slice(0, -3);
const decodedUri = decodeURIComponent(originalUri);
return virtualDocumentContents.get(decodedUri);
}
});
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: 'file', language: 'html1' }],
middleware: {
provideCompletionItem: async (document, position, context, token, next) => {
const region = getDocumentRegions(htmlLanguageService, document);
const type = region.getLanguageAtPosition(position);
if (type === 'javascript') {
const js = region.getEmbeddedDocument('javascript');
const originalUri = document.uri.toString(true);
virtualDocumentContents.set(originalUri, js.getText());
const vdocUriString = `embedded-content://js/${encodeURIComponent(
originalUri
)}.js`;
const vdocUri = Uri.parse(vdocUriString);
return await commands.executeCommand<CompletionList>(
'vscode.executeCompletionItemProvider',
vdocUri,
position,
context.triggerCharacter
);
} |
Steps to Reproduce:
<script type="module">...</script>
// @ts-check
and import any npm packageDoes this issue occur when all extensions are disabled?: Yes
If we would do the same steps with a .js file, IntelliSense will work:
It is not working in .html however:
Error:
Cannot find module 'hydro-js'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?javascript
Tried troubleshooting:
The text was updated successfully, but these errors were encountered: