Skip to content

Async fileread #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"outFiles": [
"${workspaceRoot}/vscode-client/out/**/*.js"
],
"preLaunchTask": "compile:client"
"preLaunchTask": "compile"
}
]
}
25 changes: 2 additions & 23 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,9 @@
"version": "2.0.0",
"tasks": [
{
"taskName": "compile",
"dependsOn": [
"compile:client",
"compile:server"
],
"problemMatcher": []
},
{
"label": "compile:client",
"type": "npm",
"script": "compile:client",
"group": "build",
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc"
]
},
{
"label": "compile:server",
"label": "compile",
"type": "npm",
"script": "compile:server",
"script": "compile",
"group": "build",
"presentation": {
"panel": "dedicated",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-simple-import-sort": "^4.0.0",
"jest": "^25.3.0",
"jest": "25.0.0",
"prettier": "^1.19.1",
"ts-jest": "^25.3.1",
"ts-jest": "^25.2.1",
"typescript": "^3.8.3",
"vscode-languageserver": "^5.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"url": "https://github.com/bash-lsp/bash-language-server"
},
"engines": {
"node": "*"
"node" : ">=8.0.0"
},
"dependencies": {
"fuzzy-search": "^3.2.1",
Expand Down
11 changes: 7 additions & 4 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs'
import * as FuzzySearch from 'fuzzy-search'
import * as request from 'request-promise-native'
import * as URI from 'urijs'
import { promisify } from 'util'
import * as LSP from 'vscode-languageserver'
import * as Parser from 'web-tree-sitter'

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

const readFileAsync = promisify(fs.readFile)

type Kinds = { [type: string]: LSP.SymbolKind }

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

filePaths.forEach(filePath => {
for (const filePath of filePaths) {
const uri = `file://${filePath}`
connection.console.log(`Analyzing ${uri}`)

try {
const fileContent = fs.readFileSync(filePath, 'utf8')
const fileContent = await readFileAsync(filePath, 'utf8')
const shebang = getShebang(fileContent)
if (shebang && !isBashShebang(shebang)) {
connection.console.log(`Skipping file ${uri} with shebang "${shebang}"`)
return
continue
}

analyzer.analyze(uri, LSP.TextDocument.create(uri, 'shell', 1, fileContent))
} catch (error) {
connection.console.warn(`Failed analyzing ${uri}. Error: ${error.message}`)
}
})
}

connection.console.log(`Analyzer finished after ${getTimePassed()}`)
}
Expand Down
Loading