Skip to content

Recover from file read errors #211

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 3 commits into from
Apr 14, 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
4 changes: 4 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Bash Language Server

## 1.11.3

* Recover from file reading errors (https://github.com/bash-lsp/bash-language-server/pull/211)

## 1.11.2

* Fix invalid documentHighlight response when word cannot be found (https://github.com/bash-lsp/bash-language-server/pull/209)
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A language server for Bash",
"author": "Mads Hartmann",
"license": "MIT",
"version": "1.11.2",
"version": "1.11.3",
"publisher": "mads-hartmann",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
Expand Down
9 changes: 3 additions & 6 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FIXTURES, { FIXTURE_FOLDER } from '../../../testing/fixtures'
import { getMockConnection } from '../../../testing/mocks'
import Analyzer from '../analyser'
import { initializeParser } from '../parser'

Expand Down Expand Up @@ -113,11 +114,7 @@ describe('fromRoot', () => {

jest.spyOn(Date, 'now').mockImplementation(() => 0)

const connection: any = {
console: {
log: jest.fn(),
},
}
const connection = getMockConnection()

const newAnalyzer = await Analyzer.fromRoot({
connection,
Expand All @@ -127,7 +124,7 @@ describe('fromRoot', () => {

expect(newAnalyzer).toBeDefined()

const FIXTURE_FILES_MATCHING_GLOB = 9
const FIXTURE_FILES_MATCHING_GLOB = 10

// Intro, stats on glob, one file skipped due to shebang, and outro
const LOG_LINES = FIXTURE_FILES_MATCHING_GLOB + 4
Expand Down
61 changes: 2 additions & 59 deletions server/src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
import * as lsp from 'vscode-languageserver'

import { FIXTURE_FOLDER, FIXTURE_URI } from '../../../testing/fixtures'
import { getMockConnection } from '../../../testing/mocks'
import LspServer from '../server'
import { CompletionItemDataType } from '../types'

async function initializeServer() {
const diagnostics: Array<lsp.PublishDiagnosticsParams | undefined> = undefined
const console: any = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
log: jest.fn(),
}

const connection: jest.Mocked<lsp.Connection> = {
client: {} as any,
console,
dispose: jest.fn(),
listen: jest.fn(),
onCodeAction: jest.fn(),
onCodeLens: jest.fn(),
onCodeLensResolve: jest.fn(),
onColorPresentation: jest.fn(),
onCompletion: jest.fn(),
onCompletionResolve: jest.fn(),
onDeclaration: jest.fn(),
onDefinition: jest.fn(),
onDidChangeConfiguration: jest.fn(),
onDidChangeTextDocument: jest.fn(),
onDidChangeWatchedFiles: jest.fn(),
onDidCloseTextDocument: jest.fn(),
onDidOpenTextDocument: jest.fn(),
onDidSaveTextDocument: jest.fn(),
onDocumentColor: jest.fn(),
onDocumentFormatting: jest.fn(),
onDocumentHighlight: jest.fn(),
onDocumentLinkResolve: jest.fn(),
onDocumentLinks: jest.fn(),
onDocumentOnTypeFormatting: jest.fn(),
onDocumentRangeFormatting: jest.fn(),
onDocumentSymbol: jest.fn(),
onExecuteCommand: jest.fn(),
onExit: jest.fn(),
onFoldingRanges: jest.fn(),
onHover: jest.fn(),
onImplementation: jest.fn(),
onInitialize: jest.fn(),
onInitialized: jest.fn(),
onNotification: jest.fn(),
onPrepareRename: jest.fn(),
onReferences: jest.fn(),
onRenameRequest: jest.fn(),
onRequest: jest.fn(),
onShutdown: jest.fn(),
onSignatureHelp: jest.fn(),
onTypeDefinition: jest.fn(),
onWillSaveTextDocument: jest.fn(),
onWillSaveTextDocumentWaitUntil: jest.fn(),
onWorkspaceSymbol: jest.fn(),
sendDiagnostics: jest.fn(),
sendNotification: jest.fn(),
sendRequest: jest.fn(),
telemetry: {} as any,
tracer: {} as any,
window: {} as any,
workspace: {} as any,
}
const connection = getMockConnection()

const server = await LspServer.initialize(connection, {
rootPath: FIXTURE_FOLDER,
Expand Down
19 changes: 11 additions & 8 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ export default class Analyzer {
const uri = `file://${filePath}`
connection.console.log(`Analyzing ${uri}`)

const fileContent = fs.readFileSync(filePath, 'utf8')

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

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

analyzer.analyze(uri, LSP.TextDocument.create(uri, 'shell', 1, fileContent))
})

connection.console.log(`Analyzer finished after ${getTimePassed()}`)
Expand Down
1 change: 1 addition & 0 deletions testing/fixtures/broken-symlink.sh
64 changes: 64 additions & 0 deletions testing/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import * as lsp from 'vscode-languageserver'

export function getMockConnection(): jest.Mocked<lsp.Connection> {
const console: any = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
log: jest.fn(),
}

return {
client: {} as any,
console,
dispose: jest.fn(),
listen: jest.fn(),
onCodeAction: jest.fn(),
onCodeLens: jest.fn(),
onCodeLensResolve: jest.fn(),
onColorPresentation: jest.fn(),
onCompletion: jest.fn(),
onCompletionResolve: jest.fn(),
onDeclaration: jest.fn(),
onDefinition: jest.fn(),
onDidChangeConfiguration: jest.fn(),
onDidChangeTextDocument: jest.fn(),
onDidChangeWatchedFiles: jest.fn(),
onDidCloseTextDocument: jest.fn(),
onDidOpenTextDocument: jest.fn(),
onDidSaveTextDocument: jest.fn(),
onDocumentColor: jest.fn(),
onDocumentFormatting: jest.fn(),
onDocumentHighlight: jest.fn(),
onDocumentLinkResolve: jest.fn(),
onDocumentLinks: jest.fn(),
onDocumentOnTypeFormatting: jest.fn(),
onDocumentRangeFormatting: jest.fn(),
onDocumentSymbol: jest.fn(),
onExecuteCommand: jest.fn(),
onExit: jest.fn(),
onFoldingRanges: jest.fn(),
onHover: jest.fn(),
onImplementation: jest.fn(),
onInitialize: jest.fn(),
onInitialized: jest.fn(),
onNotification: jest.fn(),
onPrepareRename: jest.fn(),
onReferences: jest.fn(),
onRenameRequest: jest.fn(),
onRequest: jest.fn(),
onShutdown: jest.fn(),
onSignatureHelp: jest.fn(),
onTypeDefinition: jest.fn(),
onWillSaveTextDocument: jest.fn(),
onWillSaveTextDocumentWaitUntil: jest.fn(),
onWorkspaceSymbol: jest.fn(),
sendDiagnostics: jest.fn(),
sendNotification: jest.fn(),
sendRequest: jest.fn(),
telemetry: {} as any,
tracer: {} as any,
window: {} as any,
workspace: {} as any,
}
}