Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 51040b4

Browse files
fix: false-positive error 'ts server not found' if project wasn't open
1 parent 51c2675 commit 51040b4

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/main.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
1818

1919
startServerProcess(projectPath) {
2020
this.supportedExtensions = atom.config.get('ide-typescript.javascriptSupport') ? allExtensions : tsExtensions
21+
const serverPath = this.getServerPath(projectPath)
22+
console.info(`starting typescript server: ${serverPath}`)
23+
2124
return super.spawnChildNode([
2225
'node_modules/typescript-language-server/lib/cli',
2326
'--stdio',
24-
'--tsserver-path', this.getServerPath(projectPath)
27+
'--tsserver-path', serverPath
2528
], { cwd: path.join(__dirname, '..') })
2629
}
2730

@@ -44,6 +47,8 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
4447

4548
shouldStartForEditor(editor) {
4649
const projectPath = this.getProjectPath(editor.getURI() || '');
50+
if (!projectPath) return false
51+
4752
if (atom.config.get('ide-typescript.ignoreFlow') === true) {
4853
const flowConfigPath = path.join(projectPath, '.flowconfig')
4954
if (fs.existsSync(flowConfigPath)) return false
@@ -79,12 +84,20 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
7984
}
8085

8186
getServerPath(projectPath) {
82-
const tsSpecifiedPath = atom.config.get('ide-typescript.typeScriptServer.path')
83-
const localPath = path.resolve(projectPath, tsSpecifiedPath)
84-
if (fs.existsSync(localPath)) {
85-
return localPath
87+
const relativePathSpecifiedByUser = atom.config.get('ide-typescript.typeScriptServer.path')
88+
const relativePathDefault = 'node_modules/typescript/lib/tsserver.js'
89+
const absPathLocal = path.resolve(projectPath, relativePathSpecifiedByUser)
90+
const absPathGlobal = path.resolve(__dirname, '..', relativePathSpecifiedByUser)
91+
const absPathGlobalDefault = path.resolve(__dirname, '..', relativePathDefault)
92+
93+
if (fs.existsSync(absPathLocal)) {
94+
return absPathLocal
8695
}
87-
return path.resolve(__dirname, '..', tsSpecifiedPath)
96+
if (fs.existsSync(absPathGlobal)) {
97+
return absPathGlobal
98+
}
99+
100+
return absPathGlobalDefault
88101
}
89102

90103
createTimeoutPromise(milliseconds, cancelPromise) {

0 commit comments

Comments
 (0)