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

Commit 9b60b9d

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

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
4444

4545
shouldStartForEditor(editor) {
4646
const projectPath = this.getProjectPath(editor.getURI() || '');
47+
if (!projectPath) return false
48+
4749
if (atom.config.get('ide-typescript.ignoreFlow') === true) {
4850
const flowConfigPath = path.join(projectPath, '.flowconfig')
4951
if (fs.existsSync(flowConfigPath)) return false
@@ -79,12 +81,20 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
7981
}
8082

8183
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
84+
const relativePathSpecifiedByUser = atom.config.get('ide-typescript.typeScriptServer.path')
85+
const relativePathDefault = 'node_modules/typescript/lib/tsserver.js'
86+
const absPathLocal = path.resolve(projectPath, relativePathSpecifiedByUser)
87+
const absPathGlobal = path.resolve(__dirname, '..', relativePathSpecifiedByUser)
88+
const absPathGlobalDefault = path.resolve(__dirname, '..', relativePathDefault)
89+
90+
if (fs.existsSync(absPathLocal)) {
91+
return absPathLocal
92+
}
93+
if (fs.existsSync(absPathGlobal)) {
94+
return absPathGlobal
8695
}
87-
return path.resolve(__dirname, '..', tsSpecifiedPath)
96+
97+
return absPathGlobalDefault
8898
}
8999

90100
createTimeoutPromise(milliseconds, cancelPromise) {

0 commit comments

Comments
 (0)