Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit d2ee449

Browse files
committed
Initial commit
0 parents  commit d2ee449

20 files changed

+6996
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
trim_trailing_whitespace = true
7+
8+
[{npm-shrinkwrap.json,package.json}]
9+
indent_style = space
10+
indent_size = 2

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules/
2+
lib/
3+
types/
4+
*.log
5+
*.swp
6+
*.swo
7+
.DS_Store
8+
9+
test-workspace

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src/
2+
typedef/
3+
e2e/
4+
*.test.js

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) base project [2017] [Quramy], Modifications copyright Microsoft 2017
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Prototype CSS TS Server Plugin
2+
3+
4+
5+
Code forked from: https://github.com/Quramy/ts-graphql-plugin

e2e/project-fixture/main.ts

Whitespace-only changes.

e2e/project-fixture/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2015",
4+
"module": "commonjs",
5+
"plugins": [
6+
{ "name": "../../../lib", "tag": "css" }
7+
]
8+
}
9+
}

e2e/run.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const createServer = require('./server-fixture');
2+
const path = require('path');
3+
const glob = require('glob');
4+
5+
function run() {
6+
const files = glob.sync('specs/*.js', {
7+
cwd: __dirname,
8+
});
9+
const specs = files.reduce((queue, file) => {
10+
return queue.then(() => {
11+
let spec;
12+
try {
13+
spec = require(path.join(__dirname, file));
14+
} catch (e) {
15+
console.error(`${file} is not server spec...`);
16+
return Promise.reject(e);
17+
}
18+
const server = createServer();
19+
return spec(server).then(() => server.close());
20+
});
21+
}, Promise.resolve(null));
22+
specs.then(() => {
23+
console.log(`🌟 ${files.length} specs were passed.`);
24+
}).catch(reason => {
25+
console.log('😢 some specs were failed...');
26+
console.error(reason);
27+
process.exit(1);
28+
});
29+
}
30+
31+
run();

e2e/server-fixture/index.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { fork } = require('child_process');
2+
const path = require('path');
3+
const readline = require('readline');
4+
5+
class TSServer {
6+
constructor() {
7+
const tsserverPath = require.resolve('typescript/lib/tsserver');
8+
const server = fork(tsserverPath, {
9+
cwd: path.join(__dirname, '../project-fixture'),
10+
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
11+
});
12+
this._exitPromise = new Promise((resolve, reject) => {
13+
server.on('exit', code => resolve(code));
14+
server.on('error', reason => reject(reason));
15+
});
16+
server.stdout.setEncoding('utf-8');
17+
readline.createInterface({
18+
input: server.stdout
19+
}).on('line', line => {
20+
if (line[0] === '{') {
21+
this.responses.push(JSON.parse(line));
22+
}
23+
})
24+
25+
this._isClosed = false;
26+
this._server = server;
27+
this._seq = 0;
28+
this.responses = [];
29+
}
30+
31+
send(command) {
32+
const seq = ++this._seq;
33+
const req = JSON.stringify(Object.assign({ seq: seq, type: 'request' }, command)) + '\n';
34+
this._server.stdin.write(req);
35+
}
36+
37+
close() {
38+
if (!this._isClosed) {
39+
this._isClosed = true;
40+
this._server.stdin.end();
41+
}
42+
return this._exitPromise;
43+
}
44+
}
45+
46+
function createServer() {
47+
return new TSServer();
48+
}
49+
50+
module.exports = createServer;

e2e/specs/completions.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const assert = require('assert');
2+
3+
function run(server) {
4+
server.send({ command: 'open', arguments: { file: './main.ts', fileContent: 'const q = css`.a { color:`', scriptKindName: "TS" } });
5+
server.send({ command: 'completions', arguments: { file: 'main.ts', offset: 26, line: 1, prefix: '' } });
6+
return server.close().then(() => {
7+
assert.equal(server.responses.length, 3);
8+
assert.equal(server.responses[2].body.length, 157);
9+
assert(server.responses[2].body.some(item => item.name === 'aliceblue'));
10+
});
11+
}
12+
13+
module.exports = run;

0 commit comments

Comments
 (0)