Skip to content

Remove sometimes useless missing node diagnostics #708

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 2 commits into from
Feb 1, 2023
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

## 4.6.2

- Remove diagnostics for missing nodes that turns out to be unstable (this was introduced in 4.5.3) https://github.com/bash-lsp/bash-language-server/pull/708

## 4.6.1

- Fix the ShellCheck code action feature that for some clients did not return any code actions. https://github.com/bash-lsp/bash-language-server/pull/700
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": "4.6.1",
"version": "4.6.2",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
"bin": {
Expand Down
22 changes: 2 additions & 20 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,13 @@ describe('analyze', () => {
expect(loggerWarn).not.toHaveBeenCalled()
})

it('parses files with a missing nodes and return relevant diagnostics', async () => {
it('parses files with a missing nodes', async () => {
const analyzer = await getAnalyzer({})
const diagnostics = analyzer.analyze({
uri: CURRENT_URI,
document: FIXTURE_DOCUMENT.MISSING_NODE,
})
expect(diagnostics).toMatchInlineSnapshot(`
[
{
"message": "Syntax error: "fi" missing",
"range": {
"end": {
"character": 0,
"line": 12,
},
"start": {
"character": 0,
"line": 12,
},
},
"severity": 2,
"source": "bash-language-server",
},
]
`)
expect(diagnostics).toEqual([])
expect(loggerWarn).toHaveBeenCalledWith(
'Error while parsing dummy-uri.sh: syntax error',
)
Expand Down
6 changes: 1 addition & 5 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ export default class Analyzer {
logger.warn(`Error while parsing ${uri}: syntax error`)
}

const missingNodesDiagnostics = TreeSitterUtil.getDiagnosticsForMissingNodes(
tree.rootNode,
)

return diagnostics.concat(missingNodesDiagnostics)
return diagnostics
}

/**
Expand Down
27 changes: 3 additions & 24 deletions server/src/util/tree-sitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode-languageserver/node'
import * as LSP from 'vscode-languageserver/node'
import { SyntaxNode } from 'web-tree-sitter'

/**
Expand All @@ -14,8 +14,8 @@ export function forEach(node: SyntaxNode, callback: (n: SyntaxNode) => void | bo
}
}

export function range(n: SyntaxNode): Range {
return Range.create(
export function range(n: SyntaxNode): LSP.Range {
return LSP.Range.create(
n.startPosition.row,
n.startPosition.column,
n.endPosition.row,
Expand Down Expand Up @@ -56,24 +56,3 @@ export function findParent(
}
return null
}

export function getDiagnosticsForMissingNodes(node: SyntaxNode) {
const diagnostics: Diagnostic[] = []

forEach(node, (node) => {
if (node.isMissing()) {
diagnostics.push(
Diagnostic.create(
range(node),
`Syntax error: "${node.type}" missing`,
DiagnosticSeverity.Warning,
undefined,
'bash-language-server',
),
)
}
return node.hasError()
})

return diagnostics
}