Skip to content
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

Markdown code block (js) IntelliSense #143009

Closed
daKmoR opened this issue Feb 14, 2022 · 4 comments
Closed

Markdown code block (js) IntelliSense #143009

daKmoR opened this issue Feb 14, 2022 · 4 comments
Assignees
Labels
*out-of-scope Posted issue is not in scope of VS Code

Comments

@daKmoR
Copy link

daKmoR commented Feb 14, 2022

When working in markdown you do not get code intellisense while within a javascript code block.

With the following source file Calculator.js

==> REPO with code

export class Calculator {
  /**
   * @param {number} a
   * @param {number} b
   * @returns {number}
   */
  add(a, b) {
    return a + b;
  }
}

you do get code IntelliSense while within a *.js file.

Screenshot 2022-02-14 at 14 23 11

but you do NOT get it in *.md files while within a code block

Screenshot 2022-02-14 at 14 23 21

Ideas

  1. provide same code IntelliSense in js code blocks as in js files
  2. require a special meta info for code blocks with intellisense - for example:
    ```js parse
    import { Calculator } from './Calculator.js';
    const calc = new Calculator();
    calc.a
    ```
    
  3. require a special file ending like for example mdjs or jsmd

I personally would favor 1 by a LOT.

any other ideas?

@mjbvz mjbvz added the *out-of-scope Posted issue is not in scope of VS Code label Feb 14, 2022
@daKmoR
Copy link
Author

daKmoR commented Feb 14, 2022

theoretical thought - would such a feature be possible via an extension?
maybe just a very rough idea on the effort?

  1. should be possible (with a little tinkering)
  2. possible but hard (you will need to do digging in vs code core)
  3. possible but daaammmnnn (beware you will lose many days on this AND there will be dragons)
  4. nope not possible (or it would require you to fork vs code to make it possible)

I just don't have any idea if it's even remotely possible... so if it's a 1 or 2 I would look into it... if it's a 3 or 4... well in that case let's say god has decided

@mjbvz
Copy link
Collaborator

mjbvz commented Feb 14, 2022

It's possible but I'm not sold on the value added for uses vs cost of maintaining it. I'd love for someone to prove otherwise though

How I'd go about this:

  1. Write an extension that can extract the contents of fenced code blocks and put each one into its own virtual document of the corresponding language
  2. When a intellisense operation comes in for the original markdown document, map this request into the corresponding virtual document.
  3. Then translate the results of the call back from the virtual document into the markdown document (you'd have to adjust all the positions/ranges for example)

@daKmoR
Copy link
Author

daKmoR commented Feb 14, 2022

thaaankkk you for that info 💪
that might sound doable 🤔

Some background info

I'm building a static site generator where the source is often markdown. But you can use javascript on the server and clientside within the file...

but now users need to choose between

  1. nice writing experience => *.rocket.md
  2. nice intellisense => *.rocket.js

can't have it both 🙈

Example of such a markdown file

```js server
export const sourceRelativeFilePath = '10--guides/index.rocket.md';
import { layout, html } from '../recursive.data.js';
export { layout, html };

// getting intellisense here would be awesome
layout.setPageOptions(...)

// getting intellisense here would be awesome
const animals = /** @type {import('../data.js')} */ (await fetch('...').then(req => req.json()));
const animalList = animals.map(animal => html`<p>${animal.name}</p>`;
```

# List of animals

Here you find...

${animalList}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

3 participants
@daKmoR @mjbvz and others