Skip to content

Commit

Permalink
VSCode Language Server Types
Browse files Browse the repository at this point in the history
Signed-off-by: 迷渡 <[email protected]>
  • Loading branch information
justjavac committed Apr 27, 2020
1 parent f08a291 commit 921af3c
Show file tree
Hide file tree
Showing 9 changed files with 3,753 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Deno
uses: denolib/setup-deno@master
with:
deno-version: 0.x
deno-version: 0.41.0

- name: Cache Deno Generated Files
uses: actions/cache@v1
Expand Down
53 changes: 14 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
# deno-starter
# VSCode Language Server - Deno

[![tag](https://img.shields.io/github/release/denomod/deno-starter)](https://github.com/denomod/deno-starter/releases)
[![Build Status](https://github.com/denomod/deno-starter/workflows/ci/badge.svg?branch=master)](https://github.com/denomod/deno-starter/actions)
[![license](https://img.shields.io/github/license/denomod/deno-starter)](https://github.com/denomod/deno-starter/blob/master/LICENSE)
[![](https://img.shields.io/badge/deno-v0.40.0-green.svg)](https://github.com/denoland/deno)
[![tag](https://img.shields.io/github/release/denodev/deno_vscode_languageserver)](https://github.com/denodev/deno_vscode_languageserver/releases)
[![Build Status](https://github.com/denodev/deno_vscode_languageserver/workflows/ci/badge.svg?branch=master)](https://github.com/denodev/deno_vscode_languageserver/actions)
[![license](https://img.shields.io/github/license/denodev/deno_vscode_languageserver)](https://github.com/denodev/deno_vscode_languageserver/blob/master/LICENSE)
[![](https://img.shields.io/badge/deno-v0.41.0-green.svg)](https://github.com/denoland/deno)

Quickly start a Deno module.
Language server protocol implementation for VSCode. This allows implementing language services in JS/TS running on Deno.

## 🧐 What's inside?
This repository contains the code for the following Deno modules:

A quick look at the files and directories you'll see in a Deno project.
- vscode_languageserver: implement a VSCode language server using Deno as a runtime.
- vscode_languageserver_textdocument: implement text documents usable in a LSP server using Deno as a runtime.
- vscode_languageserver_protocol: the actual language server protocol definition in TypeScript.
- vscode_languageserver_types: data types used by the language server client and server.

.
├─ .github
│ └─ workflows
│ └─ ci.yml
├─ .vscode
├─ .vscode
│ ├─ extensions.json
│ └─ settings.json
├─ .gitignore
├─ CHANGELOG.md
├─ LICENSE
├─ mod_test.ts
├─ mod.ts
└─ README.md
- vscode_jsonrpc: the underlying message protocol to communicate between a client and a server.

1. **`.github\workflows\ci.yml`**: GitHub Actions.

1. **`.vscode\extensions.json`**: Workspace recommended extensions for Deno Developers.

1. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.

1. **`CHANGELOG.md`**: This file contains a curated, chronologically ordered list of notable changes for each version of a project. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

1. **`LICENSE`**: Deno is licensed under the MIT license.

1. **`mod.ts`**: Deno's default entry point. The filename mod.ts follows Rust’s convention, is shorter than index.ts, and doesn’t come with any preconceived notions about how it might work. Deno does not treat "index.js" or "index.ts" in a special way. By using these filenames, it suggests that they can be left out of the module specifier when they cannot. This is confusing.

1. **`mod_test.ts`**: Each module should come with its test as a sibling with the name `modulename_test.ts`. For example the module `foo.ts` should come with its sibling `foo_test.ts`.

1. **`README.md`**: A text file containing useful reference information about your project.
**NOTE**: vscode-languageclient: npm module to talk to a VSCode language server from a VSCode extension

### License

[deno-starter](https://github.com/denomod/deno-starter) is released under the MIT License. See the bundled [LICENSE](./LICENSE) file for details.
[deno_vscode_languageserver](https://github.com/denodev/deno_vscode_languageserver) is released under the MIT License. See the bundled [LICENSE](./LICENSE) file for details.
15 changes: 0 additions & 15 deletions mod.ts

This file was deleted.

14 changes: 0 additions & 14 deletions mod_test.ts

This file was deleted.

20 changes: 20 additions & 0 deletions types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# VSCode Language Server Types

[![tag](https://img.shields.io/github/release/denodev/deno_vscode_languageserver)](https://github.com/denodev/deno_vscode_languageserver/releases)
[![Build Status](https://github.com/denodev/deno_vscode_languageserver/workflows/ci/badge.svg?branch=master)](https://github.com/denodev/deno_vscode_languageserver/actions)

Deno module containing the types used by the VSCode language client and [Deno](https://deno.land) language server.

**Modified from [microsoft/vscode-languageserver-node's types @5120691](https://github.com/microsoft/vscode-languageserver-node/blob/5120691bf187dd608ee65efdadc86d25feb45c41/types/src/main.ts)**.

--------------

> Click [here](https://code.visualstudio.com/docs/extensions/example-language-server) for a detailed document on how
> to implement language servers for [VSCode](https://code.visualstudio.com/).
>
> ## History
>
> For the history please see the [main repository](https://github.com/Microsoft/vscode-languageserver-node/blob/master/README.md)
>
> ## License
> [MIT](https://github.com/Microsoft/vscode-languageserver-node/blob/master/License.txt)
171 changes: 171 additions & 0 deletions types/edits_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import {
assertEquals,
assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
import { TextDocument, TextEdit, Position, Range } from "./mod.ts";

const applyEdits = TextDocument.applyEdits;

Deno.test(function editsInserts(): void {
let input = TextDocument.create(
"foo://bar/f",
"html",
0,
"012345678901234567890123456789",
);
assertEquals(
applyEdits(input, [TextEdit.insert(Position.create(0, 0), "Hello")]),
"Hello012345678901234567890123456789",
);
assertEquals(
applyEdits(input, [TextEdit.insert(Position.create(0, 1), "Hello")]),
"0Hello12345678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.insert(Position.create(0, 1), "Hello"),
TextEdit.insert(Position.create(0, 1), "World"),
],
),
"0HelloWorld12345678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.insert(Position.create(0, 2), "One"),
TextEdit.insert(Position.create(0, 1), "Hello"),
TextEdit.insert(Position.create(0, 1), "World"),
TextEdit.insert(Position.create(0, 2), "Two"),
TextEdit.insert(Position.create(0, 2), "Three"),
],
),
"0HelloWorld1OneTwoThree2345678901234567890123456789",
);
});

Deno.test(function editsReplace(): void {
let input = TextDocument.create(
"foo://bar/f",
"html",
0,
"012345678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
)],
),
"012Hello678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
TextEdit.replace(
Range.create(Position.create(0, 6), Position.create(0, 9)),
"World",
),
],
),
"012HelloWorld901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
TextEdit.insert(Position.create(0, 6), "World"),
],
),
"012HelloWorld678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.insert(Position.create(0, 6), "World"),
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
],
),
"012HelloWorld678901234567890123456789",
);
assertEquals(
applyEdits(
input,
[
TextEdit.insert(Position.create(0, 3), "World"),
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
],
),
"012WorldHello678901234567890123456789",
);
});

Deno.test(function editsOverlap(): void {
let input = TextDocument.create(
"foo://bar/f",
"html",
0,
"012345678901234567890123456789",
);
assertThrows(() =>
applyEdits(
input,
[
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
TextEdit.insert(Position.create(0, 3), "World"),
],
)
);
assertThrows(() =>
applyEdits(
input,
[
TextEdit.replace(
Range.create(Position.create(0, 3), Position.create(0, 6)),
"Hello",
),
TextEdit.insert(Position.create(0, 4), "World"),
],
)
);
});

Deno.test(function editsMultiline(): void {
let input = TextDocument.create("foo://bar/f", "html", 0, "0\n1\n2\n3\n4");
assertEquals(
applyEdits(
input,
[
TextEdit.replace(
Range.create(Position.create(2, 0), Position.create(3, 0)),
"Hello",
),
TextEdit.insert(Position.create(1, 1), "World"),
],
),
"0\n1World\nHello3\n4",
);
});
Loading

0 comments on commit 921af3c

Please sign in to comment.