Skip to content

Commit

Permalink
Refactor (#16): removed global npm deps
Browse files Browse the repository at this point in the history
* chore: update readme

- edited help msg

* fix: installation no longer requires global packages

- updated readme install docs
- added `scripts/*.sh` in favor of `./setup.sh`
- updated `web-tree-sitter` dep

* fix: updated `yarn setup`
* unlinks and links the fish-lsp package
  • Loading branch information
ndonfris committed Mar 19, 2024
1 parent 0de5bcb commit 312e5ff
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 93 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ info on the [wiki](https://github.com/ndonfris/fish-lsp/wiki).__
```
3. run install commands:
```fish
yarn; # yarn install; yarn tsc -b;
./setup.sh
yarn # install dependencies
yarn setup # build the project using './script/*.sh'
```
<!-- 4. alias `fish-language-server` to the `fish-lsp` binary -->
<!-- ```fish -->
<!-- alias fish-lsp="$PWD/bin/fish-language-server" -->
<!-- ``` -->
4. build and generate completions:
```fish
fish-lsp complete --fish > ~/.config/fish/completions/fish-lsp.fish
Expand All @@ -43,7 +39,7 @@ info on the [wiki](https://github.com/ndonfris/fish-lsp/wiki).__
> configuration shown for "coc.nvim"
> lua and other language-client configuration syntax's
> can be built by fish-lsp startup-configuration <filetype>.
> Gif shows different hover documentation, goto definition, goto references and some other features.
> Demo shows different hover documentation, go-to definition, go-to references and some other features.
![usage gif](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExaWkwcDY5aTg1OGltbDV6cGh4cGU4a204cGd1aHd6MmNpMWRrZ2d1biZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/PdSL9U8GXwV8xECE8k/giphy.gif)

Expand Down Expand Up @@ -103,7 +99,4 @@ major influences on the project's overall design and structure.

- __Default Implementation Git Repos__
- [client implementation](https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common)
- [server implementation](https://github.com/microsoft/vscode-languageserver-node/tree/main/server/src/common)


<meta name="google-site-verification" content="1f_cBsyKKAA9Ugty-wlNTI1aDAAO-u4CKcAvYtYM_yU" />
- [server implementation](https://github.com/microsoft/vscode-languageserver-node/tree/main/server/src/common)
12 changes: 0 additions & 12 deletions install-script.sh

This file was deleted.

30 changes: 0 additions & 30 deletions jest.config.js

This file was deleted.

73 changes: 45 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fish-language-server",
"name": "fish-lsp",
"version": "1.0.0",
"description": "Language Server Protocol (LSP) implementation for fish-shell using typescript, tree-sitter, and node",
"description": "LSP implementation for fish/fish-shell",
"author": "ndonfris",
"license": "Apache-2.0",
"repository": {
Expand All @@ -11,34 +11,22 @@
"engines": {
"node": ">=14.16"
},
"pkg": {
"entryPoints": [
"out/cli.js"
],
"targets": [
"node14-linux-x64",
"node14-macos-x64",
"node14-win-x64"
],
"outputPath": "build"
},
"bin": {
"fish-lsp": "./out/cli.js"
},
"main": "./out/server.js",
"typings": "./out/server.d.ts",
"scripts": {
"build:wasm:pre": "npm install; pushd node_modules/tree-sitter-fish; npm install",
"build:wasm": "npm run build:wasm:pre && npm exec tree-sitter build-wasm ./grammar.js && cp tree-sitter-fish.wasm ../../src/tree-sitter-fish.wasm && popd",
"pre:clean": "rimraf lib *.tsbuildinfo out",
"rebuild": "npx tree-sitter build-wasm node_modules/tree-sitter-fish/; npx tsc -b",
"clean": "npm run pre:clean && tsc -b && chmod 755 ./out/cli.js",
"prepare:tests": "rm -f test_data/fish_files/*.fish && yarn run prepare:install:tests",
"prepare:install:tests": "cd test_data && ./install_scripts/generate_largest_fish_files.fish && cd ..",
"clean": "npm run pre:clean && tsc -b && chmod 755 ./out/cli.js && echo '' > logs.txt",
"clean-nodemodules": "rimraf out *.tsbuildinfo node_modules && yarn",
"clean:all": "rimraf out *.tsbuildinfo node_modules tree-sitter-fish.wasm",
"fresh": "npm run clean:all && yarn && yarn setup",
"test": "jest --runInBand --watch --verbose true",
"compile": "tsc -b",
"watch": "npm run clean; tsc --watch",
"exec-cli": "rm -rf out && tsc -b && chmod 755 ./out/**/*.js && node ./out/cli.js"
"compile": "npx tsc -b && chmod +x ./out/cli.js",
"watch": "npm run clean; tsc -b -w",
"build-wasm": "./scripts/build-fish-wasm.sh",
"setup": "./scripts/setup.sh"
},
"eslintIgnore": [
"!.eslintrc.cjs"
Expand All @@ -51,8 +39,6 @@
},
"dependencies": {
"@tsconfig/recommended": "^1.0.3",
"@types/marked": "^4.0.8",
"@types/marked-terminal": "^3.1.3",
"cardinal": "^2.1.1",
"chalk": "^5.2.0",
"colors": "^1.4.0",
Expand All @@ -69,13 +55,12 @@
"pkg-up": "^4.0.0",
"semver": "^7.3.7",
"tree-sitter": "^0.20.6",
"tree-sitter-fish": "github:ram02z/tree-sitter-fish",
"ts-jest": "^29.0.1",
"vscode-languageserver": "^8.1.0",
"vscode-languageserver-protocol": "^3.17.3",
"vscode-languageserver-textdocument": "1.0.8",
"vscode-uri": "^3.0.7",
"web-tree-sitter": "^0.20.8"
"web-tree-sitter": "^0.22.1"
},
"devDependencies": {
"@tsconfig/node-lts": "^20.1.1",
Expand All @@ -84,6 +69,8 @@
"@types/glob": "^8.0.0",
"@types/jest": "^29.5.5",
"@types/lua-json": "^1.0.3",
"@types/marked": "^4.0.8",
"@types/marked-terminal": "^3.1.3",
"@types/minimist": "^1.2.2",
"@types/mocha": "^10.0.1",
"@types/node": "^16.18.83",
Expand All @@ -110,5 +97,35 @@
},
"enabledApiProposals": [
"inlineCompletions"
]
}
],
"jest": {
"preset": "ts-jest",
"verbose": true,
"clearMocks": true,
"moduleFileExtensions": [
"ts",
"js",
"json",
"node"
],
"modulePathIgnorePatterns": [
"<rootDir>/out"
],
"bail": 1,
"moduleNameMapper": {
"^completion/(.*)$": "<rootDir>/src/utils/completion/$1",
"^utils/(.*)$": "<rootDir>/src/utils/$1",
"^test-data/(.*)$": "<rootDir>/test-data/$1"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/"
],
"transform": {
"^.+\\.ts?$": "ts-jest",
"^.+\\.js?$": "babel-jest"
},
"testRegex": "\\.test\\.ts$",
"testTimeout": 8000,
"maxWorkers": "50%/4"
}
}
7 changes: 7 additions & 0 deletions scripts/build-fish-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

yarn add web-tree-sitter
yarn add --dev tree-sitter-cli https://github.com/ram02z/tree-sitter-fish
npx tree-sitter build-wasm node_modules/tree-sitter-fish

yarn remove tree-sitter-cli tree-sitter-fish
19 changes: 19 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env fish
yarn install
yarn build-wasm
yarn compile

echo -e "\n\nLINKING fish-lsp"
if command -vq fish-lsp
echo -e \
' "fish-lsp" is already installed\n' \
' UNLINKING and LINKING again'
yarn unlink --global-folder "fish-lsp" &> /dev/null
end
yarn link --global-folder "fish-lsp" &> /dev/null

echo -e '\n"fish-lsp" is now installed and linked'
# 'fish-lsp:'(which fish-lsp)\n\
# '> fish-lsp show-path'
#
# fish-lsp show-path
6 changes: 0 additions & 6 deletions setup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/diagnostics/syntaxError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getReturnSiblings(node: SyntaxNode) : SyntaxNode[] {
let current : SyntaxNode | null = node;
let results: SyntaxNode[] = [];
while (current) {
if (!current.isNamed()) continue;
if (!current.isNamed) continue;
results.unshift(current)
if (isReturn(current)) {
current = current.nextNamedSibling;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/completion/inline-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export namespace Line {
if (wordNode && isPartialForLoop(wordNode)) {
const completeForLoop = ["for", "i", "in", "_"];
const errorNode = firstAncestorMatch(wordNode, (n) =>
n.hasError()
n.hasError
)!;
const leafs = getLeafs(errorNode);
virtualEOLChars =
Expand Down
2 changes: 1 addition & 1 deletion src/utils/configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ export function bareStartupManger() {
export function mainStartupManager() {
const map = new ConfigMap()
return map.setup(true)
}
}
4 changes: 2 additions & 2 deletions src/utils/node-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxNode } from 'web-tree-sitter'
import { SyntaxNode } from 'web-tree-sitter';
import {ancestorMatch, findChildNodes, findFirstParent, findFirstNamedSibling, firstAncestorMatch, getChildNodes, getParentNodes, getSiblingNodes, getLeafs} from './tree-sitter';
import * as VariableTypes from './variable-syntax-nodes'

Expand Down Expand Up @@ -650,7 +650,7 @@ export function isPartialForLoop(node: SyntaxNode) {
}
if (!errorNode) return false
return (
errorNode.hasError() &&
errorNode.hasError &&
errorNode.text.startsWith("for") &&
!errorNode.text.includes(" in ")
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tree-sitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function getNamedChildNodes(root: SyntaxNode): SyntaxNode[] {
let result: SyntaxNode[] = []
while (queue.length) {
let current : SyntaxNode | undefined = queue.shift()
if (current && current.isNamed()) result.push(current)
if (current && current.isNamed) result.push(current)
if (current && current.children) queue.unshift(...current.children)
}
return result
Expand Down

0 comments on commit 312e5ff

Please sign in to comment.