Skip to content

Commit 6858f2e

Browse files
authored
Merge pull request #213 from bash-lsp/async-fileread
Async fileread
2 parents f11f305 + 8f77d43 commit 6858f2e

File tree

6 files changed

+533
-545
lines changed

6 files changed

+533
-545
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"outFiles": [
1515
"${workspaceRoot}/vscode-client/out/**/*.js"
1616
],
17-
"preLaunchTask": "compile:client"
17+
"preLaunchTask": "compile"
1818
}
1919
]
2020
}

.vscode/tasks.json

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,9 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"taskName": "compile",
6-
"dependsOn": [
7-
"compile:client",
8-
"compile:server"
9-
],
10-
"problemMatcher": []
11-
},
12-
{
13-
"label": "compile:client",
14-
"type": "npm",
15-
"script": "compile:client",
16-
"group": "build",
17-
"presentation": {
18-
"panel": "dedicated",
19-
"reveal": "never"
20-
},
21-
"problemMatcher": [
22-
"$tsc"
23-
]
24-
},
25-
{
26-
"label": "compile:server",
5+
"label": "compile",
276
"type": "npm",
28-
"script": "compile:server",
7+
"script": "compile",
298
"group": "build",
309
"presentation": {
3110
"panel": "dedicated",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"eslint-plugin-jest": "^22.17.0",
2727
"eslint-plugin-prettier": "^3.1.2",
2828
"eslint-plugin-simple-import-sort": "^4.0.0",
29-
"jest": "^25.3.0",
29+
"jest": "25.0.0",
3030
"prettier": "^1.19.1",
31-
"ts-jest": "^25.3.1",
31+
"ts-jest": "^25.2.1",
3232
"typescript": "^3.8.3",
3333
"vscode-languageserver": "^5.2.1"
3434
},

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"url": "https://github.com/bash-lsp/bash-language-server"
1616
},
1717
"engines": {
18-
"node": "*"
18+
"node" : ">=8.0.0"
1919
},
2020
"dependencies": {
2121
"fuzzy-search": "^3.2.1",

server/src/analyser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs'
22
import * as FuzzySearch from 'fuzzy-search'
33
import * as request from 'request-promise-native'
44
import * as URI from 'urijs'
5+
import { promisify } from 'util'
56
import * as LSP from 'vscode-languageserver'
67
import * as Parser from 'web-tree-sitter'
78

@@ -13,6 +14,8 @@ import { getFilePaths } from './util/fs'
1314
import { getShebang, isBashShebang } from './util/shebang'
1415
import * as TreeSitterUtil from './util/tree-sitter'
1516

17+
const readFileAsync = promisify(fs.readFile)
18+
1619
type Kinds = { [type: string]: LSP.SymbolKind }
1720

1821
type Declarations = { [name: string]: LSP.SymbolInformation[] }
@@ -62,23 +65,23 @@ export default class Analyzer {
6265
`Glob resolved with ${filePaths.length} files after ${getTimePassed()}`,
6366
)
6467

65-
filePaths.forEach(filePath => {
68+
for (const filePath of filePaths) {
6669
const uri = `file://${filePath}`
6770
connection.console.log(`Analyzing ${uri}`)
6871

6972
try {
70-
const fileContent = fs.readFileSync(filePath, 'utf8')
73+
const fileContent = await readFileAsync(filePath, 'utf8')
7174
const shebang = getShebang(fileContent)
7275
if (shebang && !isBashShebang(shebang)) {
7376
connection.console.log(`Skipping file ${uri} with shebang "${shebang}"`)
74-
return
77+
continue
7578
}
7679

7780
analyzer.analyze(uri, LSP.TextDocument.create(uri, 'shell', 1, fileContent))
7881
} catch (error) {
7982
connection.console.warn(`Failed analyzing ${uri}. Error: ${error.message}`)
8083
}
81-
})
84+
}
8285

8386
connection.console.log(`Analyzer finished after ${getTimePassed()}`)
8487
}

0 commit comments

Comments
 (0)