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

feat: add initial intellisense #226

Merged
merged 88 commits into from
Jan 12, 2023
Merged

feat: add initial intellisense #226

merged 88 commits into from
Jan 12, 2023

Conversation

remcohaszing
Copy link
Member

@remcohaszing remcohaszing commented Sep 8, 2022

This is a proof of concept for MDX intellisense support for multiple editors. The idea is to turn this repository into a monorepo.

The following packages have been added:

  • @mdx-js/language-service handles the actual logic needed for intellisense features. It provides a JavaScript API implementing interfaces from vscode-languageserver-types. It wraps the TypeScript language service interface and handles MDX syntax.
  • @mdx-js/language-server provides @mdx-js/language-service as an actual language server. This package is supposed to be consumed by projects such as NeoVim, vim-lsp, sublimelsp, and Emacs lsp-mode.
  • @mdx-js/monaco integrates @mdx-js/language-service into Monaco editor.
  • vscode-mdx provides @mdx-js/language-server as a VSCode plugin. Currently the VSCode extension is the monorepo root and the client code lives in @mdx-js/language-client, but I think it makes sense to merge both into a (private) package vscode-mdx. vsce doesn’t seem to support npm workspaces.

Closes #165 (Intellisense is a broad concept. Please open new issues for specific missing features.)
Closes #196 (I did use parts of this for inspiration. Thanks @Kingwl!)
Closes #223

This is a proof of concept for MDX intellisense support for multiple
editors. The idea is to turn this repository into a monorepo.

The following packages have been added:

- `@mdx-js/language-service` handles the actual logic needed for
  intellisense features. It provides a JavaScript API implementing
  interfaces from `vscode-languageserver-types`.
- `@mdx-js/language-server` provides `@mdx-js/language-service` as an
  actual language server. This package is supposed to be consumed by
  projects such as NeoVim, `vim-lsp`, `sublimelsp`, and Emacs
  `lsp-mode`.
- `@mdx-js/monaco` integrates `@mdx-js/language-service` into Monaco
  editor.
- `vscode-mdx` provides `@mdx-js/language-server` as a VSCode plugin.
  Currently the VSCode extension is the monorepo root and the client
  code lives in `@mdx-js/language-client`, but I think it makes sense to
  merge both into a (private) package `vscode-mdx`.

The current implementation is still very raw. It just provides definitions
for link references. The next big step is to integrate TypeScript.
@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2022

🦋 Changeset detected

Latest commit: ad45694

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

📊 Package size report   No changes

File Before After
Total (Includes all files) 29.7 kB 29.7 kB
Tarball size 12.4 kB 12.4 kB
Unchanged files
File Size
.changeset/config.json 312 B
.changeset/README.md 510 B
.commitlintrc 35 B
.editorconfig 161 B
.eslintignore 32 B
.eslintrc 191 B
.github/FUNDING.yml 234 B
.github/workflows/ci.yml 551 B
.github/workflows/pkg-size.yml 496 B
.github/workflows/publish.yml 1.2 kB
.github/workflows/release.yml 323 B
.github/workflows/version.yml 853 B
.lintstagedrc.js 46 B
.prettierrc 24 B
.remarkrc 42 B
.renovaterc 35 B
.simple-git-hooks.js 51 B
.vscode/launch.json 540 B
.vscodeignore 103 B
.yarnrc 20 B
assets/mdx.png 3.3 kB
CHANGELOG.md 3.9 kB
language-configuration.jsonc 1.1 kB
LICENSE 1.1 kB
package.json 4.6 kB
patches/eslint-mdx+2.0.2.patch 796 B
README.md 7.3 kB
syntaxes/mdx.tmLanguage.json 1.3 kB
test/component.js 54 B
test/fixture.mdx 423 B

🤖 This report was automatically generated by pkg-size-action

yarn.lock Outdated Show resolved Hide resolved
packages/language-service/lib/location-links.js Outdated Show resolved Hide resolved
.eslintrc Outdated Show resolved Hide resolved
@remcohaszing
Copy link
Member Author

I think this is now usable enough to be released as an experimental feature. I.e. it could be opt-in using a boolean setting mdx.experimentalLanguageServer.

@remcohaszing remcohaszing marked this pull request as ready for review October 25, 2022 13:04
@remcohaszing
Copy link
Member Author

remcohaszing commented Jan 6, 2023

As far as I’m concerned, this PR is ready. CI is failing due to an azure PPA outage. I would love CI to pass though, given the impact of these changes. To anyone who has permissions (including myself): Feel free to retrigger whenever you feel like it.

@remcohaszing

This comment was marked as off-topic.

.changeset/intellisense.md Show resolved Hide resolved
.github/workflows/main.yml Show resolved Hide resolved
demo/src/index.js Show resolved Hide resolved
demo/package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
packages/language-server/README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,340 @@
#!/usr/bin/env node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very few comments here, would be useful to explain what does what

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO all code in this file is fairly self-explanatory. Is something specific unclear?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s the core file that integrates all user events with certain actions in utilities.
I think this is the place where you can explain what user actions will result in what “computer responses”.
For example, in the connection.onHover handler, you can explain what a user has
to do to trigger this event, and what we’re going to do in response.
This might seem really clear (well, user has to hover, something will be shown in response), but, reading that code, I can see that you call some utility, but I don’t know what you do with that, why does it always return TypeScript that can be wrapped in a fenced code block ```ts?
Or, reading connection.onPrepareRename, what will it do? What is the difference between prepare and request?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these are just copy-pasted from other implementations. I.e. I looked at some TypeScript language servers I found, the official TypeScript integration in VSCode, the Monaco editor TypeScript integration. I don’t know why it’s formatted like that, but it works and it’s consistently used like that in the ecosystem.

I don’t really feel the need to document each request type, because it’s already explained in the LSP specification.

packages/language-service/lib/index.js Show resolved Hide resolved
packages/monaco/lib/convert.js Show resolved Hide resolved
@wooorm
Copy link
Member

wooorm commented Jan 6, 2023

To dos after:

  • Go through “marketing” material, as in, examples, but also docs
  • Perhaps add tools like stylint for CSS in demos?
  • Lowercase readme.md, license?

Q: What are other things that should be checked / improved / added later?

@remcohaszing
Copy link
Member Author

remcohaszing commented Jan 6, 2023

More todos:

I intend to create more detailed issues for these once this PR gets merged.

demo/src/index.js Show resolved Hide resolved
@remcohaszing remcohaszing merged commit 0fdf371 into mdx-js:main Jan 12, 2023
@remcohaszing
Copy link
Member Author

IntelliSense is now released behind a flag. More info on how to try it out here: https://github.com/mdx-js/vscode-mdx/releases/tag/v1.1.0. And see also the announcement on Twitter: https://twitter.com/remcohaszing/status/1613910319805382657

@karlhorky
Copy link

Amazing, thanks @remcohaszing 🙌 Long journey to get this to the state where it is now, kudos on that!

@karlhorky
Copy link

I wanted to ask where the correct place to report issues is, because I ran into a first issue trying to parse MDX which uses JavaScript inside Front Matter, as below:

---
courseModules: [{ courseId: 3, slug: 'changes' }]
---

# Changes

...more content...

The error from tsMDX is:

Could not parse expression with acorn: Unexpected content after expression(tsMDX)

Screenshot:

Screenshot 2023-01-14 at 18 45 32

I guess it's possible that I'm also using MDX in an unexpected / incorrect way here, maybe there's something I need to change...

@remcohaszing
Copy link
Member Author

@karlhorky Thanks for trying this out!

The issue tracker of this project is the right place to report. However, the issue you’re running into has already been reported: #266. The public interface for that feature requires some discussion though. I welcome any input in the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 👍 phase/yes Post is accepted and can be worked on 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Support for Code Folding on Markdown Headings [feat] IntelliSense support
6 participants