Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f4eeb12

Browse files
authored
Merge pull request #78 from mads-hartmann/add-missing-nodes-warning
Add missing nodes warning + grammar update
2 parents 4e4ac92 + 1e3d55c commit f4eeb12

File tree

9 files changed

+75
-12
lines changed

9 files changed

+75
-12
lines changed

‎server/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Bash Language Server
22

3+
## 1.5.3
4+
5+
* Support for showing warning for missing nodes
6+
* Upgrade `tree-sitter-bash` to `0.13.3`
7+
38
## 1.5.2
49

510
* Upgrade `tree-sitter` to `0.13.5` and `tree-sitter-bash` to `0.13.2`

‎server/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "1.5.2",
6+
"version": "1.5.3",
77
"publisher": "mads-hartmann",
88
"main": "out/server.js",
99
"bin": {
@@ -21,7 +21,7 @@
2121
"request": "^2.83.0",
2222
"request-promise-native": "^1.0.5",
2323
"tree-sitter": "^0.13.5",
24-
"tree-sitter-bash": "^0.13.2",
24+
"tree-sitter-bash": "^0.13.3",
2525
"turndown": "^4.0.2",
2626
"urijs": "^1.19.1",
2727
"vscode-languageserver": "^4.1.1"

‎server/src/__tests__/__snapshots__/analyzer.test.ts.snap‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`analyze returns a list of errors for a file with errors 1`] = `
3+
exports[`analyze returns a list of errors for a file with a missing node 1`] = `
4+
Array [
5+
Object {
6+
"message": "Syntax error: expected \\"fi\\" somewhere in the file",
7+
"range": Object {
8+
"end": Object {
9+
"character": 0,
10+
"line": 12,
11+
},
12+
"start": Object {
13+
"character": 0,
14+
"line": 12,
15+
},
16+
},
17+
"severity": 2,
18+
},
19+
]
20+
`;
21+
22+
exports[`analyze returns a list of errors for a file with parsing errors 1`] = `
423
Array [
524
Object {
625
"message": "Failed to parse expression",

‎server/src/__tests__/analyzer.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ beforeEach(() => {
99
})
1010

1111
describe('analyze', () => {
12-
it('returns an empty list for a file with no errors', () => {
12+
it('returns an empty list of errors for a file with no parsing errors', () => {
1313
const result = analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
1414
expect(result).toEqual([])
1515
})
1616

17-
it('returns a list of errors for a file with errors', () => {
17+
it('returns a list of errors for a file with a missing node', () => {
18+
const result = analyzer.analyze(CURRENT_URI, FIXTURES.MISSING_NODE)
19+
expect(result).not.toEqual([])
20+
expect(result).toMatchSnapshot()
21+
})
22+
23+
it('returns a list of errors for a file with parsing errors', () => {
1824
const result = analyzer.analyze(CURRENT_URI, FIXTURES.PARSE_PROBLEMS)
1925
expect(result).not.toEqual([])
2026
expect(result).toMatchSnapshot()

‎server/src/analyser.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default class Analyzer {
241241

242242
const problems = []
243243

244-
TreeSitterUtil.forEach(tree.rootNode, n => {
244+
TreeSitterUtil.forEach(tree.rootNode, (n: Parser.SyntaxNode) => {
245245
if (n.type === 'ERROR') {
246246
problems.push(
247247
LSP.Diagnostic.create(
@@ -277,6 +277,22 @@ export default class Analyzer {
277277
}
278278
})
279279

280+
function findMissingNodes(node: Parser.SyntaxNode) {
281+
if (node.isMissing()) {
282+
problems.push(
283+
LSP.Diagnostic.create(
284+
TreeSitterUtil.range(node),
285+
`Syntax error: expected "${node.type}" somewhere in the file`,
286+
LSP.DiagnosticSeverity.Warning,
287+
),
288+
)
289+
} else if (node.hasError()) {
290+
node.children.forEach(findMissingNodes)
291+
}
292+
}
293+
294+
findMissingNodes(tree.rootNode)
295+
280296
return problems
281297
}
282298

‎server/yarn.lock‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ tr46@^1.0.1:
839839
dependencies:
840840
punycode "^2.1.0"
841841

842-
tree-sitter-bash@^0.13.2:
843-
version "0.13.2"
844-
resolved "https://registry.yarnpkg.com/tree-sitter-bash/-/tree-sitter-bash-0.13.2.tgz#e3a0b049df7edf0bea74b8bf58f29241e3c73463"
842+
tree-sitter-bash@^0.13.3:
843+
version "0.13.3"
844+
resolved "https://registry.yarnpkg.com/tree-sitter-bash/-/tree-sitter-bash-0.13.3.tgz#b9d3bebb0ff9ddc3692b2a96a02872beef5af53f"
845845
dependencies:
846846
nan "^2.10.0"
847847
prebuild-install "^5.0.0"

‎testing/fixtures.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import * as LSP from 'vscode-languageserver'
44

55
const base = path.join(__dirname, './fixtures/')
66

7+
function getFixture(filename: string) {
8+
return LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, filename), 'utf8'))
9+
}
10+
711
const FIXTURES = {
8-
INSTALL: LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, 'install.sh'), 'utf8')),
9-
PARSE_PROBLEMS: LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, 'parse-problems.sh'), 'utf8')),
12+
MISSING_NODE: getFixture('missing-node.sh'),
13+
INSTALL: getFixture('install.sh'),
14+
PARSE_PROBLEMS: getFixture('parse-problems.sh'),
1015
}
1116

1217
export default FIXTURES

‎testing/fixtures/missing-node.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
# set -x
3+
set -e
4+
5+
PATH_INPUT=src/in.js
6+
PATH_OUTPUT=src/out.js
7+
8+
if [[ $PATH_INPUT -nt $PATH_OUTPUT ]]; then
9+
babel --compact false ${PATH_INPUT} > ${PATH_OUTPUT}
10+
f
11+
12+
echo "test"

‎vscode-client/src/extension.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
import { getServerInfo } from './util'
1212

13-
const MINIMUM_SERVER_VERSION = '1.3.0'
13+
const MINIMUM_SERVER_VERSION = '1.5.2'
1414

1515
export async function activate(context: ExtensionContext) {
1616
try {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /