Skip to content

Commit d45379d

Browse files
committed
chore: use @types/vscode and vscode-test instead of vscode package
1 parent 87b0a4f commit d45379d

24 files changed

+423
-870
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.vscode-test
12
lib
23
node_modules

.eslintrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.eslintrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { all } = require('eslint-config-1stg/overrides')
2+
3+
module.exports = {
4+
extends: '1stg',
5+
overrides: [
6+
...all,
7+
{
8+
files: '*.ts',
9+
rules: {
10+
'@typescript-eslint/no-floating-promises': 0,
11+
},
12+
},
13+
],
14+
}

.lintstagedrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"prettier --write",
44
"git add"
55
],
6-
"*.{mdx,ts}": [
6+
"*.{mdx,ts,tsx}": [
77
"eslint",
88
"git add"
99
]

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22

3-
node_js: stable
3+
node_js: --lts
44

55
cache: yarn
66

@@ -11,6 +11,5 @@ before_install:
1111
- git config --global user.email '[email protected]'
1212

1313
script:
14-
- set -e
1514
- yarn lint
16-
- yarn compile
15+
- yarn build

.vscodeignore

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
.vscode/**
2-
**/*.ts
3-
**/*.map
4-
.gitignore
5-
**/tsconfig.json
6-
**/tsconfig.base.json
7-
contributing.md
8-
.travis.yml
9-
client/node_modules/**
10-
!client/node_modules/vscode-jsonrpc/**
11-
!client/node_modules/vscode-languageclient/**
12-
!client/node_modules/vscode-languageserver-protocol/**
13-
!client/node_modules/vscode-languageserver-types/**
14-
!client/node_modules/semver/**
1+
.*
2+
*.log
3+
*.ts
4+
*.map
5+
tsconfig.json
6+
tsconfig.base.json
7+
tsconfig.tsbuildinfo
8+
node_modules
9+
yarn.lock
10+
!/node_modules/vscode-jsonrpc/**
11+
!/node_modules/vscode-languageclient/**
12+
!/node_modules/vscode-languageserver-protocol/**
13+
!/node_modules/vscode-languageserver-types/**
14+
!/node_modules/semver/**

.yarnrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ignore-engines true

README.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
1-
# LSP Example
1+
# [Visual Studio Code](https://code.visualstudio.com) extension for [MDX]
22

3-
Heavily documented sample code for https://code.visualstudio.com/api/language-extensions/language-server-extension-guide
3+
Adds language support for [MDX].
44

5-
## Functionality
5+
## Installation
66

7-
This Language Server works for plain text file. It has the following language features:
8-
- Completions
9-
- Diagnostics regenerated on each file change or configuration change
7+
You can install this extension from the [Marketplace](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx).
108

11-
It also includes an End-to-End test.
9+
## What about `.md` files?
1210

13-
## Structure
11+
By default the MDX language is applied only to `.mdx` files. If MDX files in your project end with `.md`, you can tell VS Code that by adding the following to your workspace settings:
1412

13+
```json
14+
"files.associations": {
15+
"*.md": "mdx"
16+
},
1517
```
16-
.
17-
├── client // Language Client
18-
│ ├── src
19-
│ │ ├── test // End to End tests for Language Client / Server
20-
│ │ └── extension.ts // Language Client entry point
21-
├── package.json // The extension manifest.
22-
└── server // Language Server
23-
└── src
24-
└── server.ts // Language Server entry point
18+
19+
## Auto-close tags
20+
21+
If you want VS Code to automatically close tags while you type, you can install [Auto Close Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag) and configure it to also include the language `mdx`:
22+
23+
```json
24+
"auto-close-tag.activationOnLanguage": [
25+
"xml",
26+
"php",
27+
"...",
28+
"mdx"
29+
]
2530
```
2631

27-
## Running the Sample
28-
29-
- Run `npm install` in this folder. This installs all necessary npm modules in both the client and server folder
30-
- Open VS Code on this folder.
31-
- Press Ctrl+Shift+B to compile the client and server.
32-
- Switch to the Debug viewlet.
33-
- Select `Launch Client` from the drop down.
34-
- Run the launch config.
35-
- If you want to debug the server as well use the launch configuration `Attach to Server`
36-
- In the [Extension Development Host] instance of VSCode, open a document in 'plain text' language mode.
37-
- Type `j` or `t` to see `Javascript` and `TypeScript` completion.
38-
- Enter text content such as `AAA aaa BBB`. The extension will emit diagnostics for all words in all-uppercase.
32+
[mdx]: https://github.com/mdx-js/mdx

client/package.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
{
22
"name": "vscode-mdx-client",
3+
"version": "0.1.1",
34
"description": "Client of MDX extension for Visual Studio Code",
45
"author": "JounQin",
5-
"license": "MIT",
6-
"version": "0.1.0",
76
"publisher": "JounQin",
8-
"repository": {
9-
"type": "git",
10-
"url": "https://github.com/rx-ts/vscode-mdx"
11-
},
7+
"license": "MIT",
8+
"repository": "[email protected]:rx-ts/vscode-mdx.git",
129
"engines": {
1310
"vscode": "^1.23.0"
1411
},
15-
"scripts": {
16-
"update-vscode": "vscode-install",
17-
"postinstall": "vscode-install"
18-
},
1912
"dependencies": {
2013
"vscode-languageclient": "^5.2.1"
21-
},
22-
"devDependencies": {
23-
"vscode": "^1.1.36"
2414
}
2515
}

client/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
import * as path from 'path'
77

8-
import { workspace, ExtensionContext } from 'vscode'
98
import {
109
LanguageClient,
1110
LanguageClientOptions,
1211
ServerOptions,
1312
TransportKind,
1413
} from 'vscode-languageclient'
1514

15+
import { workspace, ExtensionContext } from 'vscode'
16+
1617
let client: LanguageClient
1718

1819
export function activate(context: ExtensionContext) {

client/src/test/completion.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import * as assert from 'assert'
77

8-
import * as vscode from 'vscode'
9-
108
import { getDocUri, activate } from './helper'
119

10+
import * as vscode from 'vscode'
11+
1212
async function testCompletion(
1313
docUri: vscode.Uri,
1414
position: vscode.Position,

client/src/test/diagnostics.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import * as assert from 'assert'
77

8-
import * as vscode from 'vscode'
9-
108
import { getDocUri, activate } from './helper'
119

10+
import * as vscode from 'vscode'
11+
1212
function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
1313
const start = new vscode.Position(sLine, sChar)
1414
const end = new vscode.Position(eLine, eChar)

client/src/test/index.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
/* --------------------------------------------------------------------------------------------
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
4-
* ------------------------------------------------------------------------------------------ */
1+
import path from 'path'
52

6-
import * as testRunner from 'vscode/lib/testrunner'
3+
import { runTests } from 'vscode-test'
74

8-
testRunner.configure({
9-
ui: 'bdd',
10-
useColors: true,
11-
timeout: 100000,
12-
})
5+
async function main() {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath = path.resolve(__dirname, '../../')
1310

14-
module.exports = testRunner
11+
// The path to the extension test script
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath = path.resolve(__dirname, './suite/index')
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath })
17+
} catch (err) {
18+
console.error('Failed to run tests')
19+
process.exit(1)
20+
}
21+
}
22+
23+
main()

client/src/test/suite/index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import path from 'path'
2+
3+
import Mocha from 'mocha'
4+
import glob from 'glob'
5+
6+
export function run(): Promise<void> {
7+
// Create the mocha test
8+
const mocha = new Mocha({
9+
ui: 'tdd',
10+
})
11+
mocha.useColors(true)
12+
13+
const testsRoot = path.resolve(__dirname, '..')
14+
15+
return new Promise((resolve, reject) => {
16+
glob('**/**.test.ts', { cwd: testsRoot }, (err, files) => {
17+
if (err) {
18+
return reject(err)
19+
}
20+
21+
// Add files to the test suite
22+
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)))
23+
24+
try {
25+
// Run the mocha test
26+
mocha.run(failures => {
27+
if (failures > 0) {
28+
reject(new Error(`${failures} tests failed.`))
29+
} else {
30+
resolve()
31+
}
32+
})
33+
} catch (err) {
34+
reject(err)
35+
}
36+
})
37+
})
38+
}

client/testFixture/fixture1.mdx renamed to client/testFixture/fixture.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Component from './component'
1+
import { Test } from './component'
22

33
export const meta = {
44
title: 'Blog Post',
@@ -16,17 +16,17 @@ Lorem ipsum dolor sit amet, consectetur adipiscing **elit**. Ut ac lobortis <b>v
1616
}
1717
```
1818

19-
<Component>{/* This is a comment */}</Component>
19+
<Test>{/* This is a comment */}</Test>
2020

21-
<Component>
21+
<Test>
2222
{/** This is a comment */}In JSX!{/** This is a comment */}
23-
</Component>
23+
</Test>
2424

25-
Inline <Component>xxxx</Component>
25+
Inline <Test>xxxx</Test>
2626

27-
Inline <Component><!-- This is a comment -->In &gt;
27+
Inline <Test><!-- This is a comment -->In &gt;
2828
JSX!<!-- This is a
29-
comment --> &gt; <!-- This is a comment --></Component>
29+
comment --> &gt; <!-- This is a comment --></Test>
3030

3131
## Subtitle
3232

0 commit comments

Comments
 (0)