Skip to content

Commit

Permalink
chore: use @types/vscode and vscode-test instead of vscode package
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Aug 8, 2019
1 parent 87b0a4f commit d45379d
Show file tree
Hide file tree
Showing 24 changed files with 423 additions and 870 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode-test
lib
node_modules
9 changes: 0 additions & 9 deletions .eslintrc

This file was deleted.

14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { all } = require('eslint-config-1stg/overrides')

module.exports = {
extends: '1stg',
overrides: [
...all,
{
files: '*.ts',
rules: {
'@typescript-eslint/no-floating-promises': 0,
},
},
],
}
2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"prettier --write",
"git add"
],
"*.{mdx,ts}": [
"*.{mdx,ts,tsx}": [
"eslint",
"git add"
]
Expand Down
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js

node_js: stable
node_js: --lts

cache: yarn

Expand All @@ -11,6 +11,5 @@ before_install:
- git config --global user.email 'admin@1stg.me'

script:
- set -e
- yarn lint
- yarn compile
- yarn build
28 changes: 14 additions & 14 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.vscode/**
**/*.ts
**/*.map
.gitignore
**/tsconfig.json
**/tsconfig.base.json
contributing.md
.travis.yml
client/node_modules/**
!client/node_modules/vscode-jsonrpc/**
!client/node_modules/vscode-languageclient/**
!client/node_modules/vscode-languageserver-protocol/**
!client/node_modules/vscode-languageserver-types/**
!client/node_modules/semver/**
.*
*.log
*.ts
*.map
tsconfig.json
tsconfig.base.json
tsconfig.tsbuildinfo
node_modules
yarn.lock
!/node_modules/vscode-jsonrpc/**
!/node_modules/vscode-languageclient/**
!/node_modules/vscode-languageserver-protocol/**
!/node_modules/vscode-languageserver-types/**
!/node_modules/semver/**
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-engines true
52 changes: 23 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
# LSP Example
# [Visual Studio Code](https://code.visualstudio.com) extension for [MDX]

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

## Functionality
## Installation

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

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

## Structure
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:

```json
"files.associations": {
"*.md": "mdx"
},
```
.
├── client // Language Client
│ ├── src
│ │ ├── test // End to End tests for Language Client / Server
│ │ └── extension.ts // Language Client entry point
├── package.json // The extension manifest.
└── server // Language Server
└── src
└── server.ts // Language Server entry point

## Auto-close tags

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`:

```json
"auto-close-tag.activationOnLanguage": [
"xml",
"php",
"...",
"mdx"
]
```

## Running the Sample

- Run `npm install` in this folder. This installs all necessary npm modules in both the client and server folder
- Open VS Code on this folder.
- Press Ctrl+Shift+B to compile the client and server.
- Switch to the Debug viewlet.
- Select `Launch Client` from the drop down.
- Run the launch config.
- If you want to debug the server as well use the launch configuration `Attach to Server`
- In the [Extension Development Host] instance of VSCode, open a document in 'plain text' language mode.
- Type `j` or `t` to see `Javascript` and `TypeScript` completion.
- Enter text content such as `AAA aaa BBB`. The extension will emit diagnostics for all words in all-uppercase.
[mdx]: https://github.com/mdx-js/mdx
16 changes: 3 additions & 13 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
{
"name": "vscode-mdx-client",
"version": "0.1.1",
"description": "Client of MDX extension for Visual Studio Code",
"author": "JounQin",
"license": "MIT",
"version": "0.1.0",
"publisher": "JounQin",
"repository": {
"type": "git",
"url": "https://github.com/rx-ts/vscode-mdx"
},
"license": "MIT",
"repository": "git@github.com:rx-ts/vscode-mdx.git",
"engines": {
"vscode": "^1.23.0"
},
"scripts": {
"update-vscode": "vscode-install",
"postinstall": "vscode-install"
},
"dependencies": {
"vscode-languageclient": "^5.2.1"
},
"devDependencies": {
"vscode": "^1.1.36"
}
}
3 changes: 2 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

import * as path from 'path'

import { workspace, ExtensionContext } from 'vscode'
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
} from 'vscode-languageclient'

import { workspace, ExtensionContext } from 'vscode'

let client: LanguageClient

export function activate(context: ExtensionContext) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/test/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import * as assert from 'assert'

import * as vscode from 'vscode'

import { getDocUri, activate } from './helper'

import * as vscode from 'vscode'

async function testCompletion(
docUri: vscode.Uri,
position: vscode.Position,
Expand Down
4 changes: 2 additions & 2 deletions client/src/test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import * as assert from 'assert'

import * as vscode from 'vscode'

import { getDocUri, activate } from './helper'

import * as vscode from 'vscode'

function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
const start = new vscode.Position(sLine, sChar)
const end = new vscode.Position(eLine, eChar)
Expand Down
31 changes: 20 additions & 11 deletions client/src/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import path from 'path'

import * as testRunner from 'vscode/lib/testrunner'
import { runTests } from 'vscode-test'

testRunner.configure({
ui: 'bdd',
useColors: true,
timeout: 100000,
})
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../')

module.exports = testRunner
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index')

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath })
} catch (err) {
console.error('Failed to run tests')
process.exit(1)
}
}

main()
38 changes: 38 additions & 0 deletions client/src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import path from 'path'

import Mocha from 'mocha'
import glob from 'glob'

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
})
mocha.useColors(true)

const testsRoot = path.resolve(__dirname, '..')

return new Promise((resolve, reject) => {
glob('**/**.test.ts', { cwd: testsRoot }, (err, files) => {
if (err) {
return reject(err)
}

// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)))

try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`))
} else {
resolve()
}
})
} catch (err) {
reject(err)
}
})
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Component from './component'
import { Test } from './component'

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

<Component>{/* This is a comment */}</Component>
<Test>{/* This is a comment */}</Test>

<Component>
<Test>
{/** This is a comment */}In JSX!{/** This is a comment */}
</Component>
</Test>

Inline <Component>xxxx</Component>
Inline <Test>xxxx</Test>

Inline <Component><!-- This is a comment -->In &gt;
Inline <Test><!-- This is a comment -->In &gt;
JSX!<!-- This is a
comment --> &gt; <!-- This is a comment --></Component>
comment --> &gt; <!-- This is a comment --></Test>

## Subtitle

Expand Down
Loading

0 comments on commit d45379d

Please sign in to comment.