Skip to content

Commit

Permalink
feat: setting up testing workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ndonfris committed May 3, 2024
1 parent 77d7b0e commit 66f21bb
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
cmd: install # will run `yarn install` command
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # if needed
# - name: Run tests
# uses: borales/actions-yarn@v4
# with:
# cmd: test-hook # will run `yarn build:prod` command
- name: Build production bundle
uses: borales/actions-yarn@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ For more detailed information about using and contributing to the fish-lsp, plea
Contributions are included across any project relevant to the project [fish-lsp-language-clients](https://github.com/ndonfris/fish-lsp-language-clients/),
[fish-lsp.dev](https://https://github.com/ndonfris/fish-lsp.dev), and [this repo](https://github.com/ndonfris/fish-lsp).
View the [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for more info.
View the [CONTRIBUTING](./docs/CONTRIBUTING.md) file for more info.
Special thanks to everyone who has helped on the project.
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/ndonfris/fish-lsp/blob/master/LICENSE) file.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/ndonfris/fish-lsp/blob/master/LICENSE) file.
43 changes: 43 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,49 @@ project is encouraged._

Upon completing a change, submit a [PR](https://github.com/ndonfris/fish-lsp/pulls).

## Recommended workflow & Helpful Insight

Since stdin/stdout are reserved for the protocol to communicate, a generally
successful method to achieve quick results, is through TDD (Test Driven
Development). Many tree-sitter helper functions have already been written, to
aid in providing useful functionality further down the release cycle.

[Currying](https://en.wikipedia.org/wiki/Currying) is a useful design pattern,
that makes iterating through the [Abstract Syntax Trees (ASTs)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) significantly
less error prone. Earlier language server protocol versions required the Nodes
in our tree items, to be stored as a flat list. Due to this reason, there has
been the need for a significant rewrite of previously working features
(diagnostics, etc...). __This would be a great place to start__, as many of
[server](../src/server.ts) providers are implemented using range based location
calculation's to abide to their prior protocol use.

Features that receive bumps in support will eventually be supported as an opt in
design through the application config _(also needs a rewrite)_. This will allow
experimental feautures to the user's who understand what they are testing. I
have included [zod](https://github.com/colinhacks/zod), as a dependency for reading in `process.env` variables to the user's configuration.

> Until this is completed, I am sorry for any unintended bugs.
## Important Tooling Provided

- [tree-sitter](https://www.google.com/search?client=firefox-b-1-d&q=web-tree-sitter) - used for data structures/algorithms, prevelant to the shell language.
- [eslint](https://eslint.org/) - used for linting and formatting
- [knip](https://github.com/webpro/knip) - used for tree-shaking and checking unused dependcies
- [commander.js](https://github.com/tj/commander.js) - used for [src/cli.ts](../src/cli.ts) and other tooling to start the server

Becoming framiliar with using the tree-sitter code, is signficantly easier while
using the previously mentioned __TDD__. Although, another helpful method is
avaliable for any neovim devlepers via the `:InspectEdit` command. This will
allow you to visualize the AST that tree-sitter parsed from fish input.

## Adding support to new Langauge Clients/Editors

Generally, all that is required is using the `fish-lsp start` command, and
specifying fish for attaching the server to a filetype. Any other fluff in this
settings, as seen in the [JSON](../README.md#client-usage) example, is only for ease of use.

Adding new client configurations, to the [fish-lsp-client's](https://github.com/ndonfris/fish-lsp-language-clients/) repo, is greatly appreciated!

## Contributors
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"clean-nodemodules": "yarn rimraf out *.tsbuildinfo node_modules && yarn install",
"clean:all": "yarn exec rimraf out *.tsbuildinfo node_modules tree-sitter-fish.wasm",
"fresh": "yarn run clean:all && yarn install && yarn run setup",
"pretest-hook": "yarn clean:all && yarn install --ignore-scripts && yarn run sh:setup",
"test-hook": "yarn jest document.test.ts node-types.test.ts fish-syntax-node.test.ts exec.test.ts logger.test.ts parser.test.ts",
"test": "yarn jest --runInBand",
"compile": "yarn tsc -b",
Expand Down
60 changes: 60 additions & 0 deletions test-data/exec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import { setLogger } from './helpers'

import path from 'path';
import {
execEscapedCommand,
execCmd,
execCompleteLine,
execCompleteSpace,
execCommandDocs,
execCommandType
} from '../src/utils/exec'


setLogger()


describe('src/utils/exec.ts tests', () => {

it('execEscapedCommand', async () => {
const output = await execEscapedCommand('pwd')
const check = path.resolve(__dirname, '..')
// const result = path.resolve(output.toString())
// console.log("esccaped:", output[0], '---', check);
expect(output[0]).toEqual(check)
})

it('execCmd', async () => {
const output = await execCmd('pwd')
const check = path.resolve(__dirname, '..')
// console.log('execCmd: ', output[0], '---', check);
expect(output[0]).toEqual(check)

})

it('execCompleteLine', async () => {
const output = await execCompleteLine('echo -')
// console.log('line: ', output.length);
expect(output.length).toEqual(4)

})

it('execCompleteSpace', async () => {
const output = await execCompleteSpace('string ')
// console.log('line: ', output.length);
expect(output.length).toEqual(17)
})

it('execCommandDocs', async () => {
const output = await execCommandDocs('end')
// console.log('docs: ', output.split('\n').length);
expect(output.split('\n').length).toBeGreaterThan(10)
})

it('execCommandType', async () => {
const output = await execCommandType('end')
// console.log('docs: ', output.split('\n').length);
expect(output).toEqual('command')
})
})

0 comments on commit 66f21bb

Please sign in to comment.