Skip to content

Commit

Permalink
Merge pull request #625 from bash-lsp/fix-background-analysis
Browse files Browse the repository at this point in the history
Background analysis: handle workspace root being a URL
  • Loading branch information
skovhus authored Dec 13, 2022
2 parents 97b5731 + ef7f44c commit 50993c5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# Bash Language Server

Bash language server implementation based on [Tree Sitter][tree-sitter] and its [grammar for Bash][tree-sitter-bash] and supports [explainshell][explainshell] and [shellcheck][shellcheck].
Bash language server that brings an IDE-like experience for bash scripts to most editors. This is based on the [Tree Sitter parser][tree-sitter-bash] and supports [explainshell][explainshell] and [shellcheck][shellcheck].

We strongly recommend that you install [shellcheck][shellcheck] to enable linting: https://github.com/koalaman/shellcheck#installing

Documentation around configuration can be found in the [config.ts](https://github.com/bash-lsp/bash-language-server/blob/main/server/src/config.ts) file.

## Features

- [x] Jump to declaration
- [x] Find references
- [x] Code Outline & Show Symbols
- [x] Highlight occurrences
- [x] Code completion
- [x] Simple diagnostics reporting
- [x] Documentation for flags on hover
- [x] Workspace symbols
- [ ] Rename symbol
- Jump to declaration
- Find references
- Code Outline & Show Symbols
- Highlight occurrences
- Code completion
- Simple diagnostics reporting
- Documentation for symbols on hover
- Workspace symbols

To be implemented:

- Rename symbol
- Better jump to declaration and find references based on scope

## Installation

Expand All @@ -28,7 +34,7 @@ On Fedora based distros:
dnf install -y nodejs-bash-language-server
```

If you encounter installation errors, ensure you have node version 12 or newer (`node --version`).
If you encounter installation errors, ensure you have node version 14 or newer (`node --version`).

### Clients

Expand Down
11 changes: 1 addition & 10 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Bash Language Server

Bash language server implementation based on [Tree Sitter][tree-sitter] and its [grammar for Bash][tree-sitter-bash]. Integrates with [explainshell][explainshell] and [shellcheck][shellcheck].

Documentation for environment variables can be found in the [config.ts][https://github.com/bash-lsp/bash-language-server/blob/main/server/src/config.ts] file.

For more information see the GitHub repository: [bash-ide/bash-language-server][https://github.com/bash-lsp/bash-language-server]

[tree-sitter]: https://github.com/tree-sitter/tree-sitter
[tree-sitter-bash]: https://github.com/tree-sitter/tree-sitter-bash
[explainshell]: https://explainshell.com/
[shellcheck]: https://www.shellcheck.net/
This folder holds the node server written in Typescript that implements the Language Server Protocol (LSP).
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"zod": "3.20.2"
},
"scripts": {
"prepublishOnly": "cd ../ && yarn run compile"
"prepublishOnly": "cd ../ && yarn run compile && cp README.md server/"
},
"devDependencies": {
"@types/fuzzy-search": "2.1.2",
Expand Down
4 changes: 3 additions & 1 deletion server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { pathToFileURL } from 'node:url'

import {
FIXTURE_DOCUMENT,
FIXTURE_FOLDER,
Expand Down Expand Up @@ -201,7 +203,7 @@ describe('findAllSourcedUris', () => {
const newAnalyzer = new Analyzer({
console: connection.console,
parser,
workspaceFolder: REPO_ROOT_FOLDER,
workspaceFolder: pathToFileURL(REPO_ROOT_FOLDER).href,
})
await newAnalyzer.initiateBackgroundAnalysis({
backgroundAnalysisMaxFiles: defaultConfig.backgroundAnalysisMaxFiles,
Expand Down
8 changes: 5 additions & 3 deletions server/src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as Process from 'child_process'
import * as Path from 'path'
import * as Process from 'node:child_process'
import * as Path from 'node:path'
import { pathToFileURL } from 'node:url'

import * as LSP from 'vscode-languageserver/node'
import { CodeAction } from 'vscode-languageserver/node'

Expand All @@ -14,7 +16,7 @@ import LspServer from '../server'
import { CompletionItemDataType } from '../types'

async function initializeServer(
{ rootPath }: { rootPath?: string } = { rootPath: FIXTURE_FOLDER },
{ rootPath }: { rootPath?: string } = { rootPath: pathToFileURL(FIXTURE_FOLDER).href },
) {
const diagnostics: Array<LSP.PublishDiagnosticsParams | undefined> = []

Expand Down
8 changes: 7 additions & 1 deletion server/src/util/fs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as os from 'node:os'
import { fileURLToPath } from 'node:url'

import * as fastGlob from 'fast-glob'
import * as os from 'os'

// from https://github.com/sindresorhus/untildify/blob/f85a087418aeaa2beb56fe2684fe3b64fc8c588d/index.js#L11
export function untildify(pathWithTilde: string): string {
Expand All @@ -18,6 +20,10 @@ export async function getFilePaths({
rootPath: string
maxItems: number
}): Promise<string[]> {
if (rootPath.startsWith('file://')) {
rootPath = fileURLToPath(rootPath)
}

const stream = fastGlob.stream([globPattern], {
absolute: true,
onlyFiles: true,
Expand Down

0 comments on commit 50993c5

Please sign in to comment.