Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 12 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ jobs:
ci:
name: Lint Codebase
runs-on: ubuntu-latest
permissions:
permissions:
contents: read
security-events: write
actions: read

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Fish Shell
uses: fish-actions/[email protected]

- name: Enable corepack
run: corepack enable

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 21.7.1

- name: Install Yarn
run: npm install -g [email protected]
node-version-file: .nvmrc
cache: yarn

- name: Install Dependencies
run: yarn install
Expand All @@ -36,4 +37,7 @@ jobs:
run: fish-lsp --help

- name: Run Lint
run: yarn lint:fix
run: yarn lint:fix

- name: Run tests
run: yarn test
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^tree-sitter$': '<rootDir>/test-data/tree-sitter-jest.js',
},
// transform: { '^.+\.ts?$': ['ts-jest', { isolatedModules: true }] }
// globals: {
// 'ts-jest': {
Expand Down
17 changes: 5 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
},
"scripts": {
"prepare": "husky",
"setup": "run-s sh:build-time sh:build-wasm",
"preinstall": "yarn install --ignore-scripts --no-progress",
"postinstall": "run-s setup compile sh:relink sh:build-completions",
"postinstall": "run-s sh:build-time compile sh:relink sh:build-completions",
"compile": "tsc -b",
"watch": "tsc -b -w",
"sh:build-completions": "fish ./scripts/build-completions.fish",
"sh:build-time": "fish ./scripts/build-time.fish",
"sh:build-wasm": "fish ./scripts/build-fish-wasm.fish",
"sh:relink": "fish ./scripts/relink-locally.fish",
"clean:all": "rimraf out *.tsbuildinfo node_modules tree-sitter-fish.wasm logs.txt",
"clean": "rimraf out node_modules",
Expand Down Expand Up @@ -74,14 +71,12 @@
]
},
"dependencies": {
"@esdmr/tree-sitter-fish": "^3.5.2-0",
"colors": "^1.4.0",
"commander": "^12.0.0",
"deepmerge": "^4.3.1",
"marked-man": "^1.3.5",
"tree-sitter": "^0.21.0",
"tsc": "^2.0.4",
"typescript": "^5.4.3",
"tree-sitter-fish": "github:ram02z/tree-sitter-fish#refs/pull/24/head",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-protocol": "3.17.5",
"vscode-languageserver-textdocument": "1.0.11",
Expand All @@ -99,7 +94,6 @@
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.4.0",
"all-contributors-cli": "^6.26.1",
"chai": "^5.1.0",
"eslint": "^8.0.1",
"eslint-config-love": "^44.0.0",
"eslint-plugin-import": "^2.25.2",
Expand All @@ -113,10 +107,9 @@
"npm-run-all": "^4.1.5",
"pinst": "^3.0.0",
"rimraf": "^5.0.5",
"tree-sitter-cli": "^0.22.2",
"tree-sitter-fish": "https://github.com/ram02z/tree-sitter-fish",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"typescript": "^5.7.2"
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
18 changes: 0 additions & 18 deletions scripts/build-fish-wasm.fish

This file was deleted.

2 changes: 1 addition & 1 deletion src/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hover, MarkupContent, MarkupKind, Position, SymbolKind, WorkspaceSymbol, URI, Location } from 'vscode-languageserver';
import Parser, { SyntaxNode, Tree } from 'web-tree-sitter';
import Parser, { SyntaxNode, Tree } from 'tree-sitter';
import * as LSP from 'vscode-languageserver';
import { isPositionWithinRange, getChildNodes } from './utils/tree-sitter';
import { LspDocument } from './document';
Expand Down
8 changes: 4 additions & 4 deletions src/diagnostics/node-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser, { SyntaxNode } from 'web-tree-sitter';
import Parser, { SyntaxNode } from 'tree-sitter';
import { isCommand, isCommandName, isCommandWithName, isIfOrElseIfConditional, isMatchingOption, isOption, isString } from '../utils/node-types';
import { getChildNodes } from '../utils/tree-sitter';

Expand Down Expand Up @@ -79,7 +79,7 @@ export function isSourceFilename(node: SyntaxNode): boolean {
const parent = node.parent;
if (!parent) return false;
if (isCommandWithName(parent, 'source') && parent.childCount === 2) {
return parent.child(1)?.equals(node) || false;
return parent.child(1)?.id === node.id || false;
}
return false;
}
Expand All @@ -92,7 +92,7 @@ export function isTestCommandVariableExpansionWithoutString(node: SyntaxNode): b
if (!isCommandWithName(parent, 'test', '[')) return false;

if (isMatchingOption(previousSibling, { shortOption: '-n' }) || isMatchingOption(previousSibling, { shortOption: '-z' })) {
return !isString(node) && !!parent.child(2) && parent.child(2)!.equals(node);
return !isString(node) && !!parent.child(2) && parent.child(2)!.id === node.id;
}

return false;
Expand Down Expand Up @@ -162,7 +162,7 @@ export function isConditionalWithoutQuietCommand(node: SyntaxNode) {
export function isVariableDefinitionWithExpansionCharacter(node: SyntaxNode) {
if (node.parent && isCommandWithName(node.parent, 'set', 'read')) {
const definition = getChildNodes(node.parent).filter(n => !isCommand(n) && !isCommandName(n) && !isOption(n)).shift();
return (node.type === 'variable_expansion' || node.text.startsWith('$')) && definition?.equals(node);
return (node.type === 'variable_expansion' || node.text.startsWith('$')) && definition?.id === node.id;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Diagnostic } from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { LspDocument } from '../document';
import { getChildNodes, getRange } from '../utils/tree-sitter';
import { findErrorCause, isExtraEnd, isZeroIndex, isSingleQuoteVariableExpansion, isAlias, isUniversalDefinition, isSourceFilename, isTestCommandVariableExpansionWithoutString, isConditionalWithoutQuietCommand, isVariableDefinitionWithExpansionCharacter } from './node-types';
Expand Down
2 changes: 1 addition & 1 deletion src/document-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { toSymbolKind } from './utils/translation';
import { equalRanges, getRange } from './utils/tree-sitter';
import { DocumentHighlight, DocumentHighlightKind } from 'vscode-languageserver';
import { SyntaxNode, Tree } from 'web-tree-sitter';
import { SyntaxNode, Tree } from 'tree-sitter';

/**
* TODO:
Expand Down
6 changes: 3 additions & 3 deletions src/document-symbol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { DocumentSymbol, SymbolKind, Range, WorkspaceSymbol, Position, Location, FoldingRange } from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { isFunctionDefinitionName, isVariableDefinitionName, refinedFindParentVariableDefinitionKeyword } from './utils/node-types';
//import { findVariableDefinitionOptions } from './utils/options';
import { DocumentSymbolDetail } from './utils/symbol-documentation-builder';
Expand Down Expand Up @@ -112,15 +112,15 @@ export namespace FishDocumentSymbol {
export function equalScopes(a: FishDocumentSymbol, b: FishDocumentSymbol): boolean {
if (a.scope.scopeNode && b.scope.scopeNode) {
if ([a.scope.scopeTag, b.scope.scopeTag].includes('inherit')) {
return a.scope.scopeNode.equals(b.scope.scopeNode);
return a.scope.scopeNode.id === b.scope.scopeNode.id;
} else if (
['global', 'universal'].includes(a.scope.scopeTag) &&
['global', 'universal'].includes(b.scope.scopeTag)
) {
return true;
}
return a.scope.scopeTag === b.scope.scopeTag &&
a.scope.scopeNode.equals(b.scope.scopeNode);
a.scope.scopeNode.id === b.scope.scopeNode.id;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hover, MarkupContent, MarkupKind } from 'vscode-languageserver-protocol/node';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
// import { hasPossibleSubCommand } from './utils/builtins';
import { execCommandDocs, execCommandType, CompletionArguments, execCompleteSpace, execCompleteCmdArgs, documentCommandDescription } from './utils/exec';
import { getChildNodes, getNodeText } from './utils/tree-sitter';
Expand Down
2 changes: 1 addition & 1 deletion src/execute-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function sourceFishBuffer(bufferName: string) {
}

export async function FishThemeDump() {
return (await execAsyncFish('fish_config theme dump')).stdout.split('\n');
return (await execAsyncFish('fish_config theme dump; or true')).stdout.split('\n');
}

export async function showCurrentTheme(buffName: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/hover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as LSP from 'vscode-languageserver';
import { Hover, MarkupKind } from 'vscode-languageserver';
import * as Parser from 'web-tree-sitter';
import * as Parser from 'tree-sitter';
import { Analyzer } from './analyze';
import { LspDocument } from './document';
import { documentationHoverProvider, enrichCommandWithFlags } from './documentation';
Expand Down
4 changes: 2 additions & 2 deletions src/inlay-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execPrintLsp } from './utils/exec';
import { isCommand, isPipe } from './utils/node-types';
import { getRange } from './utils/tree-sitter';
import { InlayHint, MarkupContent, Range } from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { Analyzer } from './analyze';
import { LspDocument } from './document';
import { containsRange } from './workspace-symbol';
Expand Down Expand Up @@ -99,7 +99,7 @@ export namespace FishInlayHint {
//import * as Locations from '../utils/locations'
//import {isCommandName, isPipe} from '../utils/node-types';
//import {execInlayHintType} from '../utils/exec';
//import { SyntaxNode } from 'web-tree-sitter';
//import { SyntaxNode } from 'tree-sitter';
//
//export class FishInlayHintsProvider {
//
Expand Down
26 changes: 3 additions & 23 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
import { resolve } from 'path';
import Parser from 'web-tree-sitter';

const _global: any = global;
import Parser from 'tree-sitter';
import fish from 'tree-sitter-fish';

export async function initializeParser(): Promise<Parser> {
if (_global.fetch) {
delete _global.fetch;
}

await Parser.init();
const parser = new Parser();

const fishLangPath = getLanguageWasmPath();
const lang = await Parser.Language.load(fishLangPath);

parser.setLanguage(lang);
parser.setLanguage(fish);
return parser;
}

export function getLanguageWasmPath(): string {
const fishLangPath = resolve(
__dirname,
'..',
'tree-sitter-fish.wasm',
);
return fishLangPath.toString();
}
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser, { SyntaxNode } from 'web-tree-sitter';
import Parser, { SyntaxNode } from 'tree-sitter';
import { initializeParser } from './parser';
import { Analyzer } from './analyze';
//import { generateCompletionList, } from "./completion";
Expand Down
2 changes: 1 addition & 1 deletion src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SignatureHelp,
SignatureInformation,
} from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { ExtendedBaseJson, PrebuiltDocumentationMap } from './utils/snippets';
import { FishAliasCompletionItem } from './utils/completion/types';
import * as NodeTypes from './utils/node-types';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/completion/inline-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser, { SyntaxNode } from 'web-tree-sitter';
import Parser, { SyntaxNode } from 'tree-sitter';
import { initializeParser } from '../../parser';
import { getChildNodes, getLeafs, getLastLeaf, firstAncestorMatch } from '../tree-sitter';
import { isUnmatchedStringCharacter, isPartialForLoop } from '../node-types';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/definition-scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import * as NodeTypes from './node-types';
import { pathToRelativeFunctionName } from './translation';
import { firstAncestorMatch, getRange, isPositionWithinRange, getParentNodes } from './tree-sitter';
Expand Down
8 changes: 4 additions & 4 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 'tree-sitter';
import { firstAncestorMatch, getParentNodes, getLeafs } from './tree-sitter';
import * as VariableTypes from './variable-syntax-nodes';

Expand All @@ -18,7 +18,7 @@ export function isShebang(node: SyntaxNode) {
if (!firstLine) {
return false;
}
if (!node.equals(firstLine)) {
if (node.id !== firstLine.id) {
return false;
}
return (
Expand Down Expand Up @@ -65,7 +65,7 @@ export function isFunctionDefinitionName(node: SyntaxNode): boolean {
if (!isFunctionDefinition(parent)) {
return false;
}
return node.type === 'word' && node.equals(funcName);
return node.type === 'word' && node.id === funcName.id;
}

/**
Expand All @@ -87,7 +87,7 @@ export function isCommandName(node: SyntaxNode) : boolean {
if (!isCommand(parent)) {
return false;
}
return node.type === 'word' && node.equals(cmdName);
return node.type === 'word' && node.id === cmdName.id;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/symbol-documentation-builder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'os';
import { SymbolKind } from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { isFunctionDefinitionName, isVariableDefinition, isProgram, isVariableDefinitionName } from './node-types';
//import { FishFlagOption, optionTagProvider } from './options';
import { symbolKindToString, uriToPath } from './translation';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/translation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentSymbol, FoldingRange, FoldingRangeKind, SelectionRange, SymbolInformation, SymbolKind, TextDocumentEdit, TextDocumentItem, TextEdit } from 'vscode-languageserver';
import * as LSP from 'vscode-languageserver';
import { SyntaxNode } from 'web-tree-sitter';
import { SyntaxNode } from 'tree-sitter';
import { URI } from 'vscode-uri';
import { findParentVariableDefinitionKeyword, isCommand, isCommandName, isComment, isFunctionDefinition, isFunctionDefinitionName, isProgram, isScope, isStatement, isString, isVariable, isVariableDefinition } from './node-types';
import { LspDocument, LspDocuments } from '../document';
Expand Down
4 changes: 2 additions & 2 deletions src/utils/tree-sitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { extname } from 'path';
//import { pathToFileURL, URL } from 'url'
import { Position, Range, URI } from 'vscode-languageserver';
import { Point, SyntaxNode, Tree } from 'web-tree-sitter';
import { Point, SyntaxNode, Tree } from 'tree-sitter';
// import { pathToFileURL } from 'url'; // typescript-language-server -> https://github.com/typescript-language-server/typescript-language-server/blob/master/src/document.ts
// import vscodeUri from 'vscode-uri'; // typescript-language-server -> https://github.com/typescript-language-server/typescript-language-server/blob/master/src/document.ts
// import { existsSync } from 'fs-extra';
Expand Down Expand Up @@ -268,7 +268,7 @@ export function descendantMatch(

export function hasNode(allNodes: SyntaxNode[], matchNode: SyntaxNode) {
for (const node of allNodes) {
if (node.equals(matchNode)) {
if (node.id === matchNode.id) {
return true;
}
}
Expand Down
Loading