Skip to content

Background analysis: handle workspace root being a URL #625

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 4 commits into from
Dec 13, 2022
Merged
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
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

@@ -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

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
@@ -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",
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,
@@ -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,
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'

@@ -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> = []

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 {
@@ -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,