Skip to content
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

Add missing nodes warning + grammar update #78

Merged
merged 5 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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.5.3

* Support for showing warning for missing nodes

## 1.5.2

* Upgrade `tree-sitter` to `0.13.5` and `tree-sitter-bash` to `0.13.2`
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.5.2",
"version": "1.5.3",
"publisher": "mads-hartmann",
"main": "out/server.js",
"bin": {
Expand Down
21 changes: 20 additions & 1 deletion server/src/__tests__/__snapshots__/analyzer.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`analyze returns a list of errors for a file with errors 1`] = `
exports[`analyze returns a list of errors for a file with a missing node 1`] = `
Array [
Object {
"message": "Syntax error: expected \\"fi\\" somewhere in the file",
"range": Object {
"end": Object {
"character": 0,
"line": 12,
},
"start": Object {
"character": 0,
"line": 12,
},
},
"severity": 2,
},
]
`;

exports[`analyze returns a list of errors for a file with parsing errors 1`] = `
Array [
Object {
"message": "Failed to parse expression",
Expand Down
10 changes: 8 additions & 2 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ beforeEach(() => {
})

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

it('returns a list of errors for a file with errors', () => {
it('returns a list of errors for a file with a missing node', () => {
const result = analyzer.analyze(CURRENT_URI, FIXTURES.MISSING_NODE)
expect(result).not.toEqual([])
expect(result).toMatchSnapshot()
})

it('returns a list of errors for a file with parsing errors', () => {
const result = analyzer.analyze(CURRENT_URI, FIXTURES.PARSE_PROBLEMS)
expect(result).not.toEqual([])
expect(result).toMatchSnapshot()
Expand Down
18 changes: 17 additions & 1 deletion server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class Analyzer {

const problems = []

TreeSitterUtil.forEach(tree.rootNode, n => {
TreeSitterUtil.forEach(tree.rootNode, (n: Parser.SyntaxNode) => {
if (n.type === 'ERROR') {
problems.push(
LSP.Diagnostic.create(
Expand Down Expand Up @@ -277,6 +277,22 @@ export default class Analyzer {
}
})

function findMissingNodes(node: Parser.SyntaxNode) {
if (node.isMissing()) {
problems.push(
LSP.Diagnostic.create(
TreeSitterUtil.range(node),
`Syntax error: expected "${node.type}" somewhere in the file`,
LSP.DiagnosticSeverity.Warning,
),
)
} else if (node.hasError()) {
node.children.forEach(findMissingNodes)
}
}

findMissingNodes(tree.rootNode)

return problems
}

Expand Down
9 changes: 7 additions & 2 deletions testing/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import * as LSP from 'vscode-languageserver'

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

function getFixture(filename: string) {
return LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, filename), 'utf8'))
}

const FIXTURES = {
INSTALL: LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, 'install.sh'), 'utf8')),
PARSE_PROBLEMS: LSP.TextDocument.create('foo', 'bar', 0, fs.readFileSync(path.join(base, 'parse-problems.sh'), 'utf8')),
MISSING_NODE: getFixture('missing-node.sh'),
INSTALL: getFixture('install.sh'),
PARSE_PROBLEMS: getFixture('parse-problems.sh'),
}

export default FIXTURES
12 changes: 12 additions & 0 deletions testing/fixtures/missing-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# set -x
set -e

PATH_INPUT=src/in.js
PATH_OUTPUT=src/out.js

if [[ $PATH_INPUT -nt $PATH_OUTPUT ]]; then
babel --compact false ${PATH_INPUT} > ${PATH_OUTPUT}
f

echo "test"
2 changes: 1 addition & 1 deletion vscode-client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

import { getServerInfo } from './util'

const MINIMUM_SERVER_VERSION = '1.3.0'
const MINIMUM_SERVER_VERSION = '1.5.2'

export async function activate(context: ExtensionContext) {
try {
Expand Down