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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
c359e8d
feat: add initial intellisense
remcohaszing Aug 26, 2022
665ac34
chore(monaco): replace Vite with Webpack
remcohaszing Sep 15, 2022
e2dae5d
feat: add TypeScript based hovers
remcohaszing Sep 22, 2022
471109d
feat: enhance TypeScript integration
remcohaszing Sep 30, 2022
adbbf39
feat: implement more intellisense features
remcohaszing Oct 9, 2022
a907d6d
feat: support diagnostics
remcohaszing Oct 10, 2022
bdcf240
feat: restore support for markdown link definition
remcohaszing Oct 11, 2022
da93ff1
fix: fix LSP definitions
remcohaszing Oct 11, 2022
14481ca
chore: some cleanups
remcohaszing Oct 11, 2022
a18dcde
feat: provide completions
remcohaszing Oct 12, 2022
73bee60
chore: move convert functions into separate modules
remcohaszing Oct 12, 2022
44024c0
chore: move processor into language service
remcohaszing Oct 12, 2022
682256f
feat: support completion in the language server
remcohaszing Oct 13, 2022
b00be7f
chore: support references in language server
remcohaszing Oct 14, 2022
ae30c6d
feat: support diagnosics in language server
remcohaszing Oct 14, 2022
7dcc219
fix: fix language service management
remcohaszing Oct 15, 2022
c94b3a6
refactor: use TypeScript’s builtin displayPartsToString
remcohaszing Oct 15, 2022
2990c31
refactor: remove console.log
remcohaszing Oct 15, 2022
7b8eec5
fix: display location links for unopened files
remcohaszing Oct 16, 2022
91c4856
refactor: use helper function to create internal host
remcohaszing Oct 18, 2022
1f113ae
chore: update yarn.lock
remcohaszing Oct 19, 2022
01f9ee7
fix: fix module resolution and caching issues
remcohaszing Oct 21, 2022
ef57e01
refactor: remove useless function body
remcohaszing Oct 21, 2022
8ad411c
fix: fix for Monaco editor
remcohaszing Oct 21, 2022
04769a0
fix: handle parsing errors
remcohaszing Oct 24, 2022
a799ce6
docs: add readmes, licenses, and package metadata
remcohaszing Oct 25, 2022
0250ef6
chore: enable v8 --nolazy when debuggin
remcohaszing Oct 27, 2022
503c1e1
fix: add MDX snapshot caching
remcohaszing Nov 8, 2022
57de2ae
fix: fix position mapping
remcohaszing Nov 10, 2022
1704c32
feat: support renaming symbols
remcohaszing Nov 10, 2022
fa783d7
Merge branch 'master' into intellisense
remcohaszing Nov 10, 2022
5ce1c3a
feat: support type definitions
remcohaszing Nov 11, 2022
7a86603
feat: implement folding ranges
remcohaszing Nov 11, 2022
a30983a
Update packages/monaco/README.md
remcohaszing Nov 17, 2022
4e8fae8
feat: support based markdown code folding
remcohaszing Nov 11, 2022
d744406
feat: provide document outline based on TypeScript
remcohaszing Nov 11, 2022
a641641
chore: remove unnecessary CSS unit
remcohaszing Nov 17, 2022
505bd53
test: add initial language server tests
remcohaszing Nov 24, 2022
65a38b9
fix: filter MDXContent from document symbols
remcohaszing Nov 24, 2022
c3c5c64
chore: update @types/node
remcohaszing Nov 24, 2022
bbf2ab9
chore: update is-core-module
remcohaszing Nov 24, 2022
39088e2
test: add tests for prepare-rename-request
remcohaszing Nov 25, 2022
90d11ff
test: add test for rename request
remcohaszing Nov 25, 2022
88fe16b
fix: fix resolving JSX runtimes
remcohaszing Dec 1, 2022
82a2996
fix: fix React types in the Monaco demo
remcohaszing Dec 2, 2022
98b71b1
chore: move demo and test fixtures into shared directory
remcohaszing Dec 8, 2022
16e1bb0
chore: fix debug launch script
remcohaszing Dec 8, 2022
331760a
chore: fix packaging quirks
remcohaszing Dec 22, 2022
9f185d7
Merge branch 'master' into intellisense
remcohaszing Dec 22, 2022
2b30787
Merge branch 'master' into intellisense
remcohaszing Dec 22, 2022
586c8fd
Merge branch 'master' into intellisense
remcohaszing Dec 23, 2022
b30846e
Refactor Monaco integration and add tests
remcohaszing Dec 23, 2022
9b1979a
Merge branch 'master' into intellisense
remcohaszing Dec 29, 2022
8fa2b0c
Fix tests
remcohaszing Dec 29, 2022
4ff0cc9
Merge branch 'main' into intellisense
remcohaszing Dec 29, 2022
cb19bff
Fix broken test
remcohaszing Dec 29, 2022
380afa8
Fix playwright install in CI
remcohaszing Dec 29, 2022
63d331e
Make language server opt-in
remcohaszing Dec 29, 2022
12a7a1c
Disable macos tests
remcohaszing Dec 29, 2022
c95ea7a
Disable Windows in CI
remcohaszing Dec 30, 2022
c1d2a04
Increase language server test timeout
remcohaszing Dec 30, 2022
e3739bb
Update README.md
remcohaszing Dec 30, 2022
2862a05
Change casing of MDX in function names
remcohaszing Dec 30, 2022
095bc46
Remove commented code
remcohaszing Dec 30, 2022
fbdda07
Update packages/language-server/README.md
remcohaszing Dec 30, 2022
faaf0e4
Apply suggestions from code review
remcohaszing Dec 30, 2022
45d01a7
Include specific extensions in demo
remcohaszing Dec 30, 2022
fdf784b
Fix IntelliSense casing
remcohaszing Dec 30, 2022
5c2dcd8
Use strict assertion mode
remcohaszing Dec 30, 2022
80ed300
Update packages/language-service/README.md
remcohaszing Dec 30, 2022
6c1a8f2
Update packages/language-service/lib/utils.js
remcohaszing Dec 30, 2022
cac60c4
Reduce boilerplate for unimplemented code
remcohaszing Dec 30, 2022
8e86b1a
Include TypeScript in the extension bundle
remcohaszing Dec 30, 2022
7f373b6
Fix some type issues
remcohaszing Jan 5, 2023
f9e8dc4
Update jsdoc
remcohaszing Jan 6, 2023
40fffdc
Fix spacing issue
remcohaszing Jan 6, 2023
7ffbaf9
Add changeset for IntelliSense
remcohaszing Jan 6, 2023
b8ef978
Set language server process title
remcohaszing Jan 6, 2023
f5cf2aa
Omit source map from production build
remcohaszing Jan 6, 2023
77d95d5
Fix IntelliSense casing
remcohaszing Jan 6, 2023
d8e8e5e
Explain MDX/TypeScript snapshot synchronization
remcohaszing Jan 6, 2023
3ff1e0c
Add readme and license to demo
remcohaszing Jan 6, 2023
0c0c981
Explain why Windows tests are disabled
remcohaszing Jan 6, 2023
c076303
Explain how one can verity MDX intellisense is working
remcohaszing Jan 6, 2023
5af2c05
Add explanations to the Monaco editor demo
remcohaszing Jan 12, 2023
23a22e2
Configure xo env
remcohaszing Jan 12, 2023
87ebb52
Include builtin TypeScript libs in VSCode bundle
remcohaszing Jan 12, 2023
ad45694
Fix .vscodeignore
remcohaszing Jan 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
!/.github
!/.*.js
/CHANGELOG.md
/out/
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"root": true,
"extends": "@1stg",
"rules": {
"no-undef": "off",
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
"import/no-unresolved": "off",
"jsdoc/no-undefined-types": "off"
},
"overrides": [
{
"files": [
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
*.log
*.tsbuildinfo
.*cache
!/.vscode
/.vscode-test
lib
node_modules
/out/
24 changes: 23 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,29 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/test/fixture.mdx"
],
"presentation": {
"hidden": true
}
},
{
"name": "Debug language server",
"type": "node",
"request": "attach",
"port": 6009,
"presentation": {
"hidden": true
}
}
],
"compounds": [
{
"preLaunchTask": "build",
"name": "Extension + Language server",
"configurations": ["Run Extension", "Debug language server"]
}
]
}
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,30 @@
},
"license": "MIT",
"private": true,
"workspaces": [
"packages/*"
],
"packageManager": "yarn@1.22.19",
"engines": {
"vscode": ">=1.0.0"
},
"main": "out/language-client.js",
"keywords": [
"mdx",
"Markdown",
"Markdown React"
],
"scripts": {
"build": "esbuild @mdx-js/language-client @mdx-js/language-server --bundle --platform=node --target=node16 --format=cjs --external:vscode --outdir=out",
"lint": "eslint . --cache -f friendly",
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0"
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
"vscode:prepublish": "yarn build --minify"
},
"devDependencies": {
"@1stg/common-config": "^7.1.1",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.4",
"esbuild": "^0.15.0",
"patch-package": "^6.4.7",
"typescript": "^4.7.4",
"yarn-deduplicate": "^5.0.2"
Expand All @@ -74,6 +81,9 @@
"prettier": "^2.7.1"
},
"icon": "assets/mdx.png",
"activationEvents": [
"onLanguage:mdx"
],
"contributes": {
"languages": [
{
Expand Down
33 changes: 33 additions & 0 deletions packages/language-client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LanguageClient, TransportKind } from 'vscode-languageclient/node.js'

/**
* @type {LanguageClient}
*/
let client

/**
* @param {import('vscode').ExtensionContext} context
*/
export async function activate(context) {
/**
* @type {import('vscode-languageclient/node.js').NodeModule}
*/
const run = {
module: context.asAbsolutePath('out/language-server.js'),
transport: TransportKind.ipc,
}

client = new LanguageClient(
'MDX',
{ run, debug: { ...run, options: { execArgv: ['--inspect=6009'] } } },
{ documentSelector: [{ scheme: 'file', language: 'mdx' }] },
)

await client.start()
}

export async function deactivate() {
if (client) {
await client.stop()
remcohaszing marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 9 additions & 0 deletions packages/language-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@mdx-js/language-client",
"version": "0.0.0",
"type": "module",
"devDependencies": {
"@types/vscode": "^1.0.0",
"vscode-languageclient": "^8.0.0"
}
}
12 changes: 12 additions & 0 deletions packages/language-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"checkJs": true,
"module": "node16",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"paths": {
"@mdx-js/language-service": ["../language-service/index.js"]
}
}
}
36 changes: 36 additions & 0 deletions packages/language-server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createMDXLanguageService } from '@mdx-js/language-service'
import {
createConnection,
ProposedFeatures,
TextDocuments,
TextDocumentSyncKind,
} from 'vscode-languageserver/node.js'
import { TextDocument } from 'vscode-languageserver-textdocument'

const connection = createConnection(ProposedFeatures.all)
const documents = new TextDocuments(TextDocument)
const languageService = createMDXLanguageService()

connection.onInitialize(() => {
languageService.initialize()

return {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Full,
definitionProvider: true,
},
}
})

connection.onDefinition(params => {
const doc = documents.get(params.textDocument.uri)

if (!doc) {
return []
}

return languageService.doLocationLinks(doc, params.position)
})

connection.listen()
documents.listen(connection)
10 changes: 10 additions & 0 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@mdx-js/language-server",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@mdx-js/language-service": "0.0.0",
"vscode-languageserver": "^8.0.0",
"vscode-languageserver-textdocument": "^1.0.0"
}
}
12 changes: 12 additions & 0 deletions packages/language-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"checkJs": true,
"module": "node16",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"paths": {
"@mdx-js/language-service": ["../language-service/index.js"]
}
}
}
5 changes: 5 additions & 0 deletions packages/language-service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* @typedef {import('./lib/index.js').MDXLanguageService} MDXLanguageService
*/

export { createMDXLanguageService } from './lib/index.js'
32 changes: 32 additions & 0 deletions packages/language-service/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @typedef {import('vscode-languageserver-textdocument').TextDocument} TextDocument
* @typedef {import('vscode-languageserver-types').LocationLink} LocationLink
* @typedef {import('vscode-languageserver-types').Position} Position
* @typedef {object} MDXLanguageService
* @property {() => void} initialize
* Initialize the language service.
* @property {(document: TextDocument, position: Position) => LocationLink[]} doLocationLinks
* Provide document links
*/

import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import { unified } from 'unified'

import { provideLocationLinks } from './location-links.js'

/**
* Create an MDX language service
*
* @returns {MDXLanguageService} The MDX language service.
*/
export function createMDXLanguageService() {
const processor = unified().use(remarkParse).use(remarkMdx)

return {
// eslint-disable-next-line no-empty-function
initialize() {},
doLocationLinks: (document, position) =>
provideLocationLinks(document, position, processor),
}
}
remcohaszing marked this conversation as resolved.
Show resolved Hide resolved
70 changes: 70 additions & 0 deletions packages/language-service/lib/location-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* @typedef {import('unified').Processor<import('mdast').Root>} Processor
* @typedef {import('mdast').Definition} Definition
* @typedef {import('mdast').LinkReference} LinkReference
* @typedef {import('vscode-languageserver-types').LocationLink} LocationLink
* @typedef {import('vscode-languageserver-types').Position} Position
* @typedef {import('vscode-languageserver-textdocument').TextDocument} TextDocument
*/

import { fromPosition } from 'unist-util-lsp'
import { visit } from 'unist-util-visit'

/**
* @param {TextDocument} document
* @param {Position} position
* @param {Processor} processor
* @returns {LocationLink[]} A list of document links.
*/
export function provideLocationLinks(document, position, processor) {
const text = document.getText()
const ast = processor.parse(text)
/** @type {LinkReference | undefined} */
let reference
/** @type {Map<string, Definition>} */
const definitions = new Map()
const positionOffset = document.offsetAt(position)

visit(
ast,
['definition', 'linkReference'],
/**
* @param {Definition | LinkReference} node
*/
node => {
const nodePos = node.position
if (node.type === 'linkReference') {
if (
nodePos &&
positionOffset >= /** @type {number} */ (nodePos.start.offset) &&
positionOffset <= /** @type {number} */ (nodePos.end.offset)
) {
reference = node
}
} else if (!definitions.has(node.identifier) && nodePos) {
definitions.set(node.identifier, node)
}
},
)

if (!reference) {
return []
}

const definition = definitions.get(reference.identifier)

if (!definition?.position) {
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
return []
}

return [
{
originSelectionRange: reference.position
? fromPosition(reference.position)
: undefined,
targetUri: document.uri,
targetRange: fromPosition(definition.position),
targetSelectionRange: fromPosition(definition.position),
},
]
}
16 changes: 16 additions & 0 deletions packages/language-service/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@mdx-js/language-service",
"version": "0.0.0",
"type": "module",
"exports": "./index.js",
"dependencies": {
"@mdx-js/mdx": "^2.0.0",
"remark-mdx": "^2.0.0",
"remark-parse": "^10.0.0",
"unified": "^10.0.0",
"unist-util-lsp": "^1.0.0",
"unist-util-visit": "^4.0.0",
"vscode-languageserver-textdocument": "^1.0.0",
"vscode-languageserver-types": "^3.0.0"
}
}
9 changes: 9 additions & 0 deletions packages/language-service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"checkJs": true,
"module": "node16",
"noEmit": true,
"skipLibCheck": true,
"strict": true
}
}
Loading