Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from gxcsoccer/first
feat: 实现单实例版本 tsserver
- Loading branch information
Showing
31 changed files
with
1,882 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
test/fixtures | ||
coverage | ||
examples/**/app/public | ||
example | ||
logs | ||
run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
.vscode | ||
test/.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const net = require('net'); | ||
const path = require('path'); | ||
|
||
const socket = net.connect(path.join(__dirname, 'xxx.sock')); | ||
|
||
socket.once('connect', () => { | ||
console.log('connect'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const TsProxyClient = require('../lib/proxy_client'); | ||
|
||
async function main() { | ||
|
||
const client = new TsProxyClient(); | ||
|
||
client.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
client.write({ | ||
seq: 1, | ||
type: 'request', | ||
command: 'open', | ||
arguments: { file: path.join(__dirname, '../lib/protocol.js') }, | ||
}); | ||
|
||
client.write({ | ||
seq: 2, | ||
type: 'request', | ||
command: 'quickinfo', | ||
arguments: { | ||
file: path.join(__dirname, '../lib/protocol.js'), | ||
line: 5, | ||
offset: 7, | ||
}, | ||
}); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const TsProxyClient = require('../lib/proxy_client'); | ||
|
||
async function main() { | ||
|
||
const client = new TsProxyClient(); | ||
|
||
client.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
// client.write({ | ||
// seq: 1, | ||
// type: 'request', | ||
// command: 'open', | ||
// arguments: { file: path.join(__dirname, '../lib/protocol.js') }, | ||
// }); | ||
|
||
client.write({ | ||
seq: 2, | ||
type: 'request', | ||
command: 'quickinfo', | ||
arguments: { | ||
file: path.join(__dirname, '../lib/protocol.js'), | ||
line: 5, | ||
offset: 7, | ||
}, | ||
}); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const cp = require('child_process'); | ||
const { PassThrough } = require('stream'); | ||
const { TrServerDecoder } = require('./lib/protocol'); | ||
|
||
const tsServerPath = path.join(path.dirname(require.resolve('typescript')), 'tsserver.js'); | ||
|
||
const proc = cp.fork(tsServerPath, [ | ||
'--useInferredProjectPerProjectRoot', | ||
'--noGetErrOnBackgroundUpdate', | ||
'--validateDefaultNpmLocation', | ||
], { | ||
silent: true, | ||
}); | ||
|
||
const pass = new PassThrough(); | ||
const decoder = new TrServerDecoder(); | ||
|
||
proc.stdout.pipe(decoder); | ||
|
||
decoder.on('message', msg => { | ||
console.log(msg); | ||
}); | ||
|
||
function encode(obj) { | ||
return JSON.stringify(obj) + '\r\n'; | ||
} | ||
|
||
proc.stdin.write(encode({ | ||
seq: 1, | ||
type: 'request', | ||
command: 'open', | ||
arguments: { file: path.join(__dirname, 'lib/tsserver_decoder.js') }, | ||
})); | ||
|
||
proc.stdin.write(encode({ | ||
seq: 2, | ||
type: 'request', | ||
command: 'quickinfo', | ||
arguments: { | ||
file: path.join(__dirname, 'lib/tsserver_decoder.js'), | ||
line: 5, | ||
offset: 7, | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const utils = require('../lib/utils'); | ||
|
||
const tsServerPath = path.join(path.dirname(require.resolve('typescript')), 'tsserver.js'); | ||
const args = [ | ||
'--useInferredProjectPerProjectRoot', | ||
'--noGetErrOnBackgroundUpdate', | ||
'--validateDefaultNpmLocation', | ||
]; | ||
const tsServerForkOptions = { | ||
silent: true, | ||
}; | ||
|
||
console.log(utils.md5(JSON.stringify({ | ||
tsServerPath, | ||
args, | ||
tsServerForkOptions, | ||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const TsProxyServer = require('../lib/proxy_server'); | ||
|
||
const tsServerPath = path.join(path.dirname(require.resolve('typescript')), 'tsserver.js'); | ||
const args = [ | ||
'--useInferredProjectPerProjectRoot', | ||
'--noGetErrOnBackgroundUpdate', | ||
'--validateDefaultNpmLocation', | ||
]; | ||
const tsServerForkOptions = { | ||
silent: true, | ||
}; | ||
|
||
const server = new TsProxyServer({ | ||
tsServerPath, | ||
args, | ||
tsServerForkOptions, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const ClusterTsServerProcess = require('../lib'); | ||
|
||
const tsServerPath = path.join(path.dirname(require.resolve('typescript')), 'tsserver.js'); | ||
const args = [ | ||
'--useInferredProjectPerProjectRoot', | ||
'--noGetErrOnBackgroundUpdate', | ||
'--validateDefaultNpmLocation', | ||
]; | ||
const tsServerForkOptions = { | ||
silent: true, | ||
}; | ||
|
||
async function main() { | ||
const proc = new ClusterTsServerProcess({ tsServerPath, args, tsServerForkOptions }); | ||
proc.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
}); | ||
await proc.ready(); | ||
|
||
proc.write({ | ||
seq: 1, | ||
type: 'request', | ||
command: 'open', | ||
arguments: { file: path.join(__dirname, '../lib/protocol.js') }, | ||
}); | ||
|
||
proc.write({ | ||
seq: 2, | ||
type: 'request', | ||
command: 'quickinfo', | ||
arguments: { | ||
file: path.join(__dirname, '../lib/protocol.js'), | ||
line: 5, | ||
offset: 7, | ||
}, | ||
}); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const ClusterTsServerProcess = require('../lib'); | ||
|
||
const options = { | ||
"tsServerPath": "/Users/gaoxiaochen/projj/gitlab.alipay-inc.com/cloud-ide/api-server/_extensions/kaitian.typescript-language-features-1.37.1-patch.12/node_modules/typescript/lib/tsserver.js", | ||
"args": [ | ||
"--useInferredProjectPerProjectRoot", | ||
"--enableTelemetry", | ||
"--cancellationPipeName", | ||
"/var/folders/q4/4nwl16wn32ndm69rzh1zyvhh0000gn/T/vscode-typescript501/e6ea02d3b441c4be4f4c/tscancellation-6ecdd2ccb16d73006bfb.tmp*", | ||
"--locale", "zh-CN", | ||
"--noGetErrOnBackgroundUpdate", | ||
"--validateDefaultNpmLocation" | ||
], | ||
"tsServerForkOptions": { | ||
"execArgv": [] | ||
} | ||
} | ||
|
||
const proc = new ClusterTsServerProcess(options); | ||
proc.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
}); | ||
|
||
proc.write({ | ||
seq: 0, | ||
type: 'request', | ||
command: 'configure', | ||
arguments: { | ||
hostInfo: 'vscode', | ||
preferences: { | ||
providePrefixAndSuffixTextForRename: true, | ||
allowRenameOfImportPath: true | ||
} | ||
} | ||
}); | ||
|
||
proc.write({ | ||
seq: 1, | ||
type: 'request', | ||
command: 'compilerOptionsForInferredProjects', | ||
arguments: { | ||
options: { | ||
module: 'commonjs', | ||
target: 'es2016', | ||
jsx: 'preserve', | ||
allowJs: true, | ||
allowSyntheticDefaultImports: true, | ||
allowNonTsExtensions: true | ||
} | ||
} | ||
}); | ||
|
||
proc.write({ | ||
"seq": 2, | ||
"type": "request", | ||
"command": "updateOpen", | ||
"arguments": { | ||
"changedFiles": [], | ||
"closedFiles": [], | ||
"openFiles": [{ | ||
"file": "/Users/gaoxiaochen/projj/gitlab.alipay-inc.com/cloud-ide/api-server/app/controller/home.ts", | ||
"fileContent": fs.readFileSync('/Users/gaoxiaochen/projj/gitlab.alipay-inc.com/cloud-ide/api-server/app/controller/home.ts', 'utf8'), | ||
"scriptKindName": "TS", | ||
"projectRootPath": "/Users/gaoxiaochen/projj/gitlab.alipay-inc.com/cloud-ide/api-server" | ||
}] | ||
} | ||
}); | ||
|
||
// setTimeout(() => { | ||
proc.write({ | ||
seq: 3, | ||
type: 'request', | ||
command: 'geterr', | ||
arguments: { | ||
delay: 0, | ||
files: ['/Users/gaoxiaochen/projj/gitlab.alipay-inc.com/cloud-ide/api-server/app/controller/home.ts'] | ||
} | ||
}); | ||
// }, 5000); | ||
|
||
proc.write({ | ||
seq: 4, | ||
type: 'request', | ||
command: 'getSupportedCodeFixes', | ||
arguments: null | ||
}); |
Oops, something went wrong.