Skip to content

Development Notes

nick edited this page May 7, 2024 · 3 revisions

Various notes

Warning

Potentially out of date. Still probably useful.

  • fish-lsp/src/server.ts is the main entry point for the language server.

  • test-data contains the test data for the language server. Here is the quickest way to get a grasp of major features.

    npm run test analyze # to test: `./fish_data/analyze.test.ts`
  • DocumentSymbol has been implemented across various branches, I still have not figured out the best way to resolve a symbol based on scope using this protocol.

  • SymbolInformation has been implemented, but was abandoned due to official documentation stating that it is deprecated. Having now used the DocumentSymbol protocol, the tree structure that this protocol avoids makes it significantly easier to implement across server handlers.

NOTE: you can not use partial result: DocumentSymbol[] | SymbolInformation[]. DocumentSymbol[] and SymbolInformation[] can not be mixed. That means the first chunk defines the type of all the other chunks.

  • node-types.ts contains the node types for the fish language. A more verbose version of tokenization via tree-sitter-fish, would make node-types.ts significantly more readable. It would also greatly simplify the process of detecting what the type of a node is. If you are interested in helping with this, please reach out
fish-shell TreeSitter.SyntaxNode.type
set --local var "value" var.type === 'word'
echo "$var" var.type === 'variable'

the above example is showing the TreeSitter.SyntaxNode containing character sequence: var

  • tree-sitter.ts contains the node flattening and searching utilities for the fish language.

Debugging && Testing

  • when testing a server handler on an actual fish file, the logger by default will print output to ~/path/to/repo/logs.txt. I typically run the following command in a separate shell, to display the logs:

    echo "" > logs.txt && tail -f logs.txt
  • when testing specific files/implementation, writing tests inside the ./test-data/ directory are typically the most effective approach.

    • you can console.log() the jest test-suites, by calling the helpers.ts function:

      import {setLogger} from './helpers'
      
      setLogger()
       
      describe("your feature to test", () => {
          it('test1', async () => {
              // ...test code...
              console.log('test1') // logs to normal console instead of jest console
          }
      })

fish shell snippets:

# get all functions
function --all | string split ','
# get all events
functions --handlers | string match -vr '^Event \w+' | string split -n '\n'
# show all variables
set --show
# show all variable names
# set --names 
# get all abbreviations
abbr --show
# get documentation for a function
functions -D -v 'function_name'
# /home/ndonfris/.config/fish/functions/function_name.fish
# autoloaded
# 3
# scope-shadowing