-- [SUMMARY](#summary)
-- [INSTALLATION](#installation)
-- [FEATURES](#features)
-- [CONTRIBUTING](./docs/CONTRIBUTING.md)
-- [ROADMAP](./docs/ROADMAP.md)
-- [WIKI](#viewing-the-wiki)
-- [SOURCES](#sources)
+![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ndonfris/fish-lsp/eslint.yml?branch=master&labelColor=%23181939)
+![License](https://img.shields.io/github/license/ndonfris/fish-lsp?&labelColor=%23181939&color=b88af3)
+![Github Created At](https://img.shields.io/github/created-at/ndonfris/fish-lsp?logo=%234e6cfa&label=created&labelColor=%23181939&color=%236198f5)
-## Summary
+A [Language Server Protocol (LSP)](https://lsif.dev/) tailored for the [fish shell](https://github.com/microsoft/vscode-languageserver-node/tree/main/server/src/common).
+This project aims to enhance the coding experience for fish, by introducing a suite of
+intelligent features like auto-completion, scope aware symbol analysis, per-token hover
+generation, and [many others](#features).
-A __feature-rich__, __extensible__, and __blazingly fast__ [language-server](https://github.com/microsoft/vscode-languageserver-node/tree/main/server/src/common) for the [fish-shell](https://fishshell.com/).
-Uses [tree-sitter](https://tree-sitter.github.io/tree-sitter/), [tree-sitter-fish](https://github.com/ram02z/tree-sitter-fish), [yarn](https://yarnpkg.com/) and [typescript](https://www.typescriptlang.org/).
-Implements both standard & non-standard features from the [language-server-protocol](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#headerPart), to be connected to a language-client ([neovim](https://neovim.io/),[coc.nvim](https://github.com/neoclide/coc.nvim), [vscode](https://code.visualstudio.com/), [etc.](https://github.com/ndonfris/fish-lsp-language-clients)).
-__More info on the [wiki](https://github.com/ndonfris/fish-lsp/wiki).__
+The LSP describes __both__ a [server](#server-usage) and [client's](#client-usage) communication abilities.
+Text editor's (_or any other equivalent form of_ __langauge client__) are then able to choose which general
+programming features will be implemented. This leaves current and future possibilities
+supported by the server open ended.
-![fish-lsp --help](https://i.imgur.com/M6Zm3yW.png)
+In short, the overall project goal is to produce an editor agnostic developer
+environment for fish.
-
-
-
-
-
+### Client Usage
-## Installation
-
-1. Create the `fish-lsp` command via one of the following methods ___(building
- from source is recommended)___
-
-
-
- Using npm (UNTESTED)
-
-
- ```fish
- npm i -g fish-lsp
- ```
-
-
-
- Build from source
-
+ ![demo.gif](https://github.com/ndonfris/fish-lsp.dev/blob/ndonfris-patch-1/new_output.gif?raw=true)
- - clone the repository
+ > [!NOTE]
+ > _Please submit other demo's in_ [show & tell](https://github.com/ndonfris/fish-lsp/discussions/categories/show-and-tell) _discussion_
- ```fish
- git clone https://github.com/ndonfris/fish-lsp.git
- ```
+### Server Usage
- - enter the directory
+
+
+
+
+
+
- ```fish
- cd ./fish-lsp
- ```
+ ![fish-lsp --help](https://github.com/ndonfris/fish-lsp.dev/blob/master/public/help-msg-new.png)
- - run the install commands:
+
- ```fish
- yarn install # install dependencies
- ```
+## Installation
-
-
- Using release binaries (UNTESTED)
+> __dependencies:__ `yarn@1.22.22`, `node@21.7.1`, `fish@3.7.1`
- > ___Currently is not recommended for use as the release binaries are error
- > prone and not fully tested. Future `tsup` builds, should provide stability
- > across different installation enviornments.___
+Building from source is __the only currently recommended installation method__, as we improve
+other methods of the installation process (Don't use __releases__ or __npm package__).
+Contributions to help enhance installation options are greatly appreciated!
- - navigate to the [releases](https://github.com/ndonfris/fish-lsp/master/releases), and download the file for your OS
+1. Clone the repo
- - Rename file to fish-lsp (make sure the binary is executable as well)
+ ```bash
+ git clone https://github.com/ndonfris/fish-lsp
+ # cd fish-lsp
+ ```
- ```fish
- # cd to downloaded location
- mv fish-lsp-linux fish-lsp
- chmod +x ./fish-lsp
- ```
+1. Install the dependencies & run the setup handler scripts
- - move the binary to your __\$PATH__:
+ ```bash
+ yarn install
+ ```
- ```fish
- mv ./fish-lsp ~/.local/bin/fish-lsp
- ```
+1. __Optional:__ Check that the project successfully compiled & linked
-
+ ```bash
+ # ./bin/fish-lsp --help
+ fish-lsp --help
+ ```
+1. Setup the project in the [client](https://github.com/ndonfris/fish-lsp/wiki/Client-Configurations) of your choice
-1. Provide the `fish-lsp` command to start the server from a language client
```json
{
- "languageserver": {
- "fish-lsp": {
- "command": "fish-lsp",
- "args": ["start"],
- "filetypes": ["fish"]
+ "fish-lsp": {
+ "command": "fish-lsp",
+ "filetypes": ["fish"],
+ "args": ["start"],
+ "revealOutputChannelOn": "info",
+ "initializationOptions": {
+ "workspaces": {
+ "paths": {
+ "defaults": [
+ "$HOME/.config/fish",
+ "/usr/share/fish"
+ ]
+ }
+ }
}
}
}
- ```
- > configuration shown for "coc.nvim"
- > lua and other language-client configuration syntax's
- > can be built by fish-lsp startup-configuration .
- > Demo shows different hover documentation, go-to definition, go-to references
- > and some other features.
-
+ ```
+
+ > neovim client using [coc.nvim](https://github.com/neoclide/coc.nvim) configuartion. Snippet located inside [coc-settings.json](https://github.com/neoclide/coc.nvim/wiki/Language-servers#register-custom-language-servers) `"languageserver"` key
+
+## Why?
+
+ The creation of this project was driven by a vision to bridge the gap in tooling for the
+ fish shell, independently separating the shell's community by text-editor/IDE.
+
+
+
+
+
+
+
+
+
+
+
- ![usage gif](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExaWkwcDY5aTg1OGltbDV6cGh4cGU4a204cGd1aHd6MmNpMWRrZ2d1biZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/PdSL9U8GXwV8xECE8k/giphy.gif)
+### Simplicity of fish's syntax
-
+ Compared to other programming languages that feature LSP implementations, the syntax and
+ language design of fish are notably straightforward. This simplicity theoretically
+ facilitates the development of language server features, making them easier to
+ conceptualize, document, and test. Additionally, the straightforward nature of fish’s
+ design lowers the barrier to entry for understanding the project's core architecture,
+ making it less daunting for users to contribute their own feature requests and enhancements.
+
+### Challenges
+
+ Since its inception, __fish-lsp__ has undergone substantial changes, requiring frequent refactoring
+ and even the temporary exclusion of certain features to maintain compatibility and performance
+ with evolving LSP standards. These modifications have often led to extensive rewrites of
+ significant sections throughout the project. As a result, some features are currently on hold until
+ they can be seamlessly integrated into the updated framework.
+
+ Your sponsorship and/or contributions are vital to continuing the development and refinement of __fish-lsp__,
+ ensuring it remains a valuable tool for the community.
## Features
@@ -134,36 +152,29 @@ __More info on the [wiki](https://github.com/ndonfris/fish-lsp/wiki).__
| __Client Tree__ | Shows the defined scope as a Tree | ✅ |
| __Indexing__ | Indexes all commands, variables, and functions | ✅ |
-## Viewing the Wiki
-The [wiki](https://github.com/ndonfris/fish-lsp/wiki) Contains more information on the project. Project is still in it's early releases, so the wiki
-information is subject to change. Contains ['minimal' client submodules](https://github.com/ndonfris/fish-lsp-language-clients),
-useful snippets, and bleeding edge feature documentation.
-
-## Sources
-This project aims to be a more feature rich alternative to some of it's predecessors,
-while maintaining an editor agnostic server implantation. The following sources were
-major influences on the project's overall design and structure.
-
-- __Official Documentation__
- - [__LSP__](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#headerPart)
- - [__LSIF__](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#headerPart)
- - [__vscode-extension-samples__](https://github.com/microsoft/vscode-extension-samples/tree/main)
- - [__Tree-Sitter__](https://tree-sitter.github.io/tree-sitter/)
- - [__Tree-Sitter-Fish__](https://github.com/ram02z/tree-sitter-fish)
-
-- __Related/Similiar projects__
- - [vscode-languageserver-node/testbed](https://github.com/microsoft/vscode-languageserver-node/tree/main/testbed)
- - [awk-language-server](https://github.com/Beaglefoot/awk-language-server/tree/master/server)
- - [bash-language-server](https://github.com/bash-lsp/bash-language-server/tree/main/server/src)
- - [coc.fish](https://github.com/oncomouse/coc-fish)
- - [typescript-language-server](https://github.com/typescript-language-server/typescript-language-server#running-the-language-server)
- - [coc-tsserver](https://github.com/neoclide/coc-tsserver)
-
-- __Important Packages__
- - [vscode-jsonrpc](https://www.npmjs.com/package/vscode-jsonrpc)
- - [vscode-languageserver](https://github.com/Microsoft/vscode-languageserver-node)
- - [vscode-languageserver-textdocument](https://github.com/Microsoft/vscode-languageserver-node)
-
-- __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)
+## Additional Resources
+
+For more detailed information about using and contributing to the fish-lsp, please visit the following resources:
+
+- [Contributing](./docs/CONTRIBUTING.md) - Docs describing how to contribute to the fish-lsp project.
+
+- [Roadmap](./docs/ROADMAP.md) - Goals for future project releases.
+
+- [Wiki](https://github.com/ndonfris/fish-lsp/wiki) - further documentation and knowledge relevant to the project
+
+- [Discussions](https://github.com/ndonfris/fish-lsp/discussions) - interact with our maintainers
+
+- [Site](https://fish-lsp.dev/) - Web Homepage
+
+- [Client Examples](https://github.com/ndonfris/fish-lsp/wiki/Client-Configurations) - Testable language client configuartions
+
+
+## Contributing
+
+Contributions are what make the open-source community such a powerful and diverse platform for development.
+
+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.
diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md
index 654d481c..f28c8ef6 100644
--- a/docs/CONTRIBUTING.md
+++ b/docs/CONTRIBUTING.md
@@ -26,3 +26,13 @@ Once these steps are complete, you can then begin testing locally. __Forking__ _
project is encouraged._
Upon completing a change, submit a [PR](https://github.com/ndonfris/fish-lsp/pulls).
+
+## Contributors
+
+
+
+
+
+
+
+
diff --git a/docs/MAN_FILE.md b/docs/MAN_FILE.md
index 72fda950..970b9de3 100644
--- a/docs/MAN_FILE.md
+++ b/docs/MAN_FILE.md
@@ -28,6 +28,9 @@ Start the language server.
`min` or `bare`
Start the language server without any language-specific features.
+`logger`
+Access the logger
+
`info`
show the build info of fish-lsp
@@ -42,31 +45,29 @@ Show help message and exit.
## EXAMPLES
-Start the `fish-lsp` language server, with the default configuration:
+ • Start the `fish-lsp` language server, with the default configuration:
-```sh
-> fish-lsp start
-```
+ ```fish
+ >_ fish-lsp start
+ ```
-Start the `fish-lsp` language server, with the bare minimum configuration:
+• Start the `fish-lsp` language server, with the bare minimum configuration:
-```sh
-> fish-lsp bare --enable hover
-```
+ ```fish
+ >_ fish-lsp bare --enable hover
+ ```
-Show the path to the `fish-lsp` language server binary:
+• Show the path to the `fish-lsp` language server binary:
-```sh
-> fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish
-```
+ ```fish
+ >_ fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish
+ ```
## SEE ALSO
-__website:__ _https://fish-lsp.dev/_
-
-__repo:__ _https://github.com/ndonfris/fish-lsp_
-
-__fish website:__ _https://fishshell.com/_
+ • __website:__ _https://fish-lsp.dev/_
+ • __repo:__ _https://github.com/ndonfris/fish-lsp_
+ • __fish website:__ _https://fishshell.com/_
## AUTHOR
diff --git a/docs/man/fish-lsp.1 b/docs/man/fish-lsp.1
index 292aabc8..0d44a2a7 100644
--- a/docs/man/fish-lsp.1
+++ b/docs/man/fish-lsp.1
@@ -37,6 +37,10 @@ Start the language server\.
.br
Start the language server without any language\-specific features\.
.P
+\fBlogger\fP
+.br
+Access the logger
+.P
\fBinfo\fP
.br
show the build info of fish\-lsp
diff --git a/package.json b/package.json
index 9b0feda5..4bbea54b 100755
--- a/package.json
+++ b/package.json
@@ -114,6 +114,7 @@
"@types/node": "^20.11.30",
"@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",
diff --git a/src/cli.ts b/src/cli.ts
index 139118b8..ee8314ac 100755
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -7,6 +7,7 @@ import * as luaJson from 'lua-json';
import { asciiLogoString, BuildCapabilityString, RepoUrl, PathObj, PackageLspVersion, GetEnvVariablesUsed, PackageVersion, accumulateStartupOptions, getBuildTimeString } from './utils/commander-cli-subcommands';
import { mainStartupManager, bareStartupManger, ConfigMap } from './utils/configuration-manager';
import { buildFishLspCompletions } from './utils/get-lsp-completions';
+import { createServerLogger, Logger, ServerLogsPath } from './logger';
export function startServer() {
// Create a connection for the server.
@@ -47,45 +48,33 @@ export function startWebscoket() {
const createFishLspBin = (): Command => {
const bin = new Command('fish-lsp');
bin.description([
- 'A language server for the `fish-shell`, written in typescript. Currently supports ',
- 'the following feature set from "' + PackageLspVersion + '" of the language server protocol.',
- 'More documentation is available for any command or subcommand via \'-h/--help\'.',
+ ` A language server for the \`fish-shell\`, written in typescript. Currently supports`,
+ ` the following feature set from "'${PackageLspVersion}'" of the language server protocol.`,
+ ' More documentation is available for any command or subcommand via \'-h/--help\'.',
'',
- 'The current language server protocol, reserves stdin/stdout for communication between the ',
- 'client and server. This means that when the server is started, it will listen for messages on',
- ' not displaying any output from the command.',
+ ' The current language server protocol, reserves stdin/stdout for communication between the ',
+ ' client and server. This means that when the server is started, it will listen for messages on',
+ ' not displaying any output from the command.',
'',
- 'For more information, see the github repository:',
- ` ${RepoUrl}`,
+ ' For more information, see the github repository:',
+ ` ${RepoUrl}`,
].join('\n'))
.version(PackageVersion, '-v, --version', 'output the version number')
.enablePositionalOptions(true)
.configureHelp({ helpWidth: 100 })
.showSuggestionAfterError()
.showHelpAfterError()
- .addHelpText('beforeAll', asciiLogoString('large') + '\n')
+ // .addHelpText('before', asciiLogoString('large') + '\n')
+ // .addHelpText('before', asciiLogoString('large') + '\n')
.addHelpText('after', [
'',
'Examples:',
' # Default setup, with all options enabled',
- ' > fish-lsp start ',
- '',
- ' # Enable only the hover provider:',
- ' > fish-lsp bare --enable hover',
+ ' >_ fish-lsp start ',
'',
' # Generate and store completions file:',
- ' > fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish',
- '',
- ' # Show debug info from build:',
- ' > fish-lsp info',
- '',
+ ' >_ fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish',
].join('\n'));
-
- // .configureHelp(help=> {
- // help.
- // })
- // .storeOptionsAsProperties();
-
return bin;
};
@@ -125,17 +114,6 @@ commandBin.command('start [TOGGLE...]')
// process.exit(0);
});
-// commandBin.command('mini')
-// .summary('subcmd to start the lsp using stdin/stdout with minimal indexing')
-// .description([
-// 'Start the language server for a connection to a client with minimal indexing.',
-// 'This is useful for large projects, where indexing can take a long time.',
-// 'Also useful for running `edit_command_buffer` (editing prompt in tmp file).',
-// ].join(' '))
-// .action(() => {
-// // const startupConfig =
-// startServer();
-// });
commandBin.command('bare [TOGGLE...]')
.alias('min')
@@ -176,14 +154,34 @@ commandBin.command('bare [TOGGLE...]')
// process.exit(0);
});
-// commandBin.command('capabilities')
-// .summary('show the capabilities of the language server')
-// .description('current capabilities of fish-lsp')
-// .action(() => {
-// console.log(asciiLogoString('large'));
-// console.log(BuildCapabilityString());
-// process.exit(0);
-// });
+
+commandBin.command('logger')
+ .summary('test the logger by displaying it')
+ .option('-s, --show', 'show the logger and don\'t edit it')
+ .option('-c, --clear', 'clear the logger')
+ .option('-d, --date', 'write the date')
+ .option('-q, --quiet', 'silence logging')
+ .option('--config', 'show the logger config')
+ .action(args => {
+ let logger = createServerLogger(ServerLogsPath, false)
+ const objArgs = Object.getOwnPropertyNames(args)
+ const argsQueue = objArgs
+ let currentArg: string = '';
+ while (argsQueue.length !== 0) {
+ currentArg = argsQueue.shift() || ''
+ if (currentArg === 'clear') logger.clearLogFile();
+ if (currentArg === 'quiet') logger.toggleSilence()
+ if (currentArg === 'date') logger.log(getBuildTimeString())
+ if (currentArg === 'config') console.log(JSON.stringify(logger.getLoggingOpts()))
+ if (currentArg === 'show') break;
+ }
+
+ if (!args.show) return
+ // if (args.show) logger.showLogfileText()
+ logger.showLogfileText()
+ return
+ })
+
commandBin.command('info')
.summary('show the build info of fish-lsp')
@@ -241,68 +239,6 @@ commandBin.command('info')
process.exit(0);
});
-// @TODO
-// .option('--vscode', 'show vscode-settings.json output')
-// commandBin.command('startup-configuration')
-// .usage('[language-option]')
-// .summary('show the json/lua configurations for the language server')
-// .description('show the lua/json configurations for the language server')
-// .option('--json', 'show coc-settings.json output')
-// .option('--lua', 'show neovim *.lua output')
-// .action(args => {
-// if (args.json) {
-// console.log('coc-settings.json');
-// console.log(JSON.stringify({'hello': "world"}, null, 2));
-// } else if (args.lua) {
-// const jsonConf = JSON.parse(JSON.stringify({"todo" : [1, 2, 3], 'hello': "world"}))
-// console.log('neovim *.lua');
-// console.log(luaJson.format(jsonConf));
-// } else {
-// console.log('no option selected, coc-settings.json is default');
-// }
-// process.exit(0);
-// })
-
-// @TODO
-// commandBin.command('time')
-// .usage('--path [dir]')
-// .summary('time the fish-lsp server startup time to index the project files')
-// .requiredOption('--path [dir]', 'root directory of the fish project')
-// .action(args => {
-// const startTimer = Date.now();
-// const config: ConfigMap = mainStartupManager();
-// if (args.path) {
-// console.log(args.path)
-//
-// const files = FastGlob.sync('**.fish', {
-// cwd: args.path,
-// absolute: true,
-// globstar: true,
-// dot: true,
-// })
-// // const parser = initializeParser();
-//
-// const parser = initializeParser();
-// const workspace = Workspace.create(args.path);
-//
-// // Promise.resolve()
-// files.map(async (file) => {
-// console.log(file);
-// const data = await readFile(file, 'utf8').then((data) => {
-// return data
-// })
-// console.log(data)
-// new Analyzer(await parser, await workspace)
-// // parser.parse(data);
-//
-// })
-//
-// // const paths: string[] = args.path || [`~/.config/fish/config.fish`];
-// // config.setKV('', value)
-// const endTimer = Date.now();
-// console.log(endTimer-startTimer, 'ms');
-// }
-// });
commandBin.command('url')
.summary('show a helpful url related to the fish-lsp')
@@ -347,41 +283,6 @@ commandBin.command('url')
process.exit(0);
});
-// commandBin.command('contribute')
-// .summary('see the fish-lsp github repo')
-// .action(() => {
-// console.log(asciiLogoString('normal'));
-// console.log(RepoUrl);
-// process.exit(0);
-// });
-//
-// commandBin.command('report')
-// .summary('report an issue to the fish-lsp github repo')
-// .action(() => {
-// console.log(asciiLogoString('normal'));
-// console.log(RepoUrl + '/issues');
-// process.exit(0);
-// });
-
-// commandBin.command('lsp-version')
-// .usage('lsp-version')
-// .summary('show the version of the language server protocol')
-// .description('show the version of the language server protocol')
-// .action(() => {
-// console.log(asciiLogoString('single') + '\n');
-// console.log('LSP version: ', PackageLspVersion);
-// process.exit(0);
-// });
-
-// commandBin.command('show-env')
-// .usage('show-env')
-// .summary('show all the environment variables used by the lsp in current shell')
-// .description('show the environment variables of the language server')
-// .action(() => {
-// console.log('Environment Variables: ' + asciiLogoString('single'));
-// console.log(GetEnvVariablesUsed());
-// process.exit(0);
-// });
// @TODO
commandBin.command('complete')
@@ -412,4 +313,4 @@ commandBin.command('complete')
process.exit(0);
});
-commandBin.parse();
+commandBin.parse();
\ No newline at end of file
diff --git a/src/logger.ts b/src/logger.ts
index cbaad8e0..10a710fb 100755
--- a/src/logger.ts
+++ b/src/logger.ts
@@ -1,44 +1,15 @@
-import {
- CompletionItem,
- Connection,
- DocumentSymbol,
- Hover,
- Position,
- RemoteConsole,
- SymbolKind,
- Range,
- ExecuteCommandParams,
-} from 'vscode-languageserver';
+// import {
+// CompletionItem,
+// Connection,
+// DocumentSymbol,
+// Hover,
+// Position,
+// RemoteConsole,
+// SymbolKind,
+// Range,
+// ExecuteCommandParams,
+// } from 'vscode-languageserver';
import * as console from 'node:console';
-//import {TextDocument} from 'vscode-languageserver-textdocument';
-//import {URI} from 'vscode-uri';
-//import { SyntaxNode } from "web-tree-sitter";
-//import {FishCompletionItem, FishCompletionItemKind} from './utils/completion-strategy';
-//import {resolve} from 'path';
-//import { appendFileSync } from 'fs';
-//
-//
-//export interface LogOptions {
-// caller?: string;
-// message?: string;
-// extraInfo?: string | string[];
-// verticalPad?: boolean;
-// error?: boolean;
-// executableFile?: string;
-// path?: string;
-// uri?: URI;
-// rootNode?: SyntaxNode;
-// nodes?: SyntaxNode[];
-// position?: Position;
-// hover?: Hover;
-// completion?: CompletionItem;
-// document?: TextDocument;
-// debugLogger?: boolean;
-//}
-
-//export class Logger {
-//private static instance : Logger;
-
//private LOGFILE: string = resolve('/home/ndonfris/repos/fish-lang-server/logs.txt')
import fs from 'fs';
@@ -55,6 +26,7 @@ type CConsole = Console;
export class Logger {
protected _console: IConsole;
+ protected _silence: boolean = true;
protected logFilePath: string;
constructor(logFilePath: string = '', clear: boolean = true, _console: IConsole = console) {
@@ -65,11 +37,19 @@ export class Logger {
}
}
+ toggleSilence() {
+ this._silence = !this._silence
+ }
+
+ hasSilence() {
+ return this._silence
+ }
+
hasLogFile(): boolean {
return this.logFilePath !== '';
}
- private clearLogFile(): void {
+ clearLogFile(): void {
try {
// fs.truncateSync(this.logFilePath, 0);
fs.writeFileSync(this.logFilePath, '')
@@ -93,10 +73,9 @@ export class Logger {
return String(arg);
}).join('\n');
- this._console.log(formattedMessage);
- if (this.hasLogFile()) {
- this.logToFile(formattedMessage);
- }
+ if (!this.hasSilence()) this._console.log(formattedMessage);
+ if (this.hasLogFile()) this.logToFile(formattedMessage);
+
}
logPropertiesForEachObject>(objs: T[], ...keys: (keyof T)[]): void {
@@ -124,6 +103,13 @@ export class Logger {
this._console.log('--- Log file text ---');
this._console.log(fs.readFileSync(this.logFilePath, 'utf-8'));
}
+
+ getLoggingOpts() {
+ return {
+ 'logFile': this.hasLogFile(),
+ 'silence': this.hasSilence(),
+ }
+ }
}
export class JestLogger extends Logger {
@@ -153,4 +139,4 @@ export function createServerLogger(logFilePath: string = '', clear: boolean = tr
export function createJestLogger(): JestLogger {
return new JestLogger();
-}
+}
\ No newline at end of file
diff --git a/src/utils/commander-cli-subcommands.ts b/src/utils/commander-cli-subcommands.ts
index 6bbf5867..5bb6b12d 100755
--- a/src/utils/commander-cli-subcommands.ts
+++ b/src/utils/commander-cli-subcommands.ts
@@ -529,4 +529,4 @@ export const getBuildTimeString = () => {
//
// complete -c fish-lsp -f -a '(_fish_lsp_completions)'`;
// console.log(script);
-// }
+// }
\ No newline at end of file
diff --git a/src/utils/configuration-manager.ts b/src/utils/configuration-manager.ts
index 3663d867..dcb170dc 100644
--- a/src/utils/configuration-manager.ts
+++ b/src/utils/configuration-manager.ts
@@ -103,4 +103,4 @@ export function bareStartupManger() {
export function mainStartupManager() {
const map = new ConfigMap();
return map.setup(true);
-}
+}
\ No newline at end of file
diff --git a/src/utils/get-lsp-completions.ts b/src/utils/get-lsp-completions.ts
index 80b9bb7a..7cc7b9bc 100644
--- a/src/utils/get-lsp-completions.ts
+++ b/src/utils/get-lsp-completions.ts
@@ -1,79 +1,191 @@
-
import { Command } from 'commander';
import { ConfigMap } from './configuration-manager';
+const AUTO_GENERATED_HEADER_STRING = `#
+# AUTO GENERATED BY 'fish-lsp'
+#
+# * Any command should generate the completions file
+#
+# >_ fish-lsp complete > ~/.config/fish/completions/fish-lsp.fish
+# >_ fish-lsp complete --fish > ~/.config/fish/completions/fish-lsp.fish
+# >_ yarn install # from inside the 'fish-lsp'
+#
+# * You can test the completions by editing:
+#
+# ~/.config/fish/completions/fish-lsp.fish
+#
+# or by using the command:
+#
+# >_ fish-lsp complete
+#
+# to visually check what is wrong
+#
+# * For more info, try editing the generated output inside:
+#
+# ~/...install_path.../fish-lsp/src/utils/get-lsp-completions.ts
+#
+`
+
+const __fish_lsp_needs_command = `
+# Returns exit code of 0 if lsp hasn't received a command yet, e.g. \`start\`
+function __fish_lsp_needs_command
+ set -l cmd (commandline -opc)
+ if test (count $cmd) -eq 1
+ return 0
+ else if test (count $cmd) -gt 1
+ for c in $cmd[2..-1]
+ switch $c
+ # Exclude options that are allowed to appear before command
+ case -v --version help
+ continue
+ case '*'
+ return 1
+ end
+ end
+ return 0
+ end
+ return 1
+end
+`
+
+const __fish_lsp_using_command = `
+# Returns exit code of 0 if any command (argv[1..-1]) appears once, ignores flags.
+function __fish_lsp_using_command
+ set -l commands $argv
+ set -l cmd (commandline -opc)
+ if test (count $cmd) -gt 1
+ set -l command_seen_once 1
+ for c in $cmd[2..-1]
+ switch $c
+ case '-*'
+ continue
+ case $commands
+ # If the command is seen more than once then return 1
+ if test $command_seen_once -eq 1
+ set command_seen_once 0
+ else
+ return 1
+ end
+ case '*'
+ if test $command_seen_once -eq 0
+ return 0
+ else
+ return 1
+ end
+ end
+ end
+ return $command_seen_once
+ end
+ return 1
+end
+`
+
+const __fish_lsp_includes_subcommand = `
+# Check if \`commandline\` contains a set of subcommands
+function __fish_lsp_includes_subcommand
+ set -l cmd (commandline -opc)
+ for subcommand in $argv
+ if contains $subcommand $cmd
+ return 0
+ end
+ end
+ return 1
+end
+`
+
+
+/**
+ * Syntax for urlCompletions does not match other completions because it is not influenced
+ * by recieving multiple duplicated arguments
+ */
+const urlCompletions: string = `# fish-lsp url --
+complete -c fish-lsp -n "__fish_seen_subcommand_from url" -a "
+--repo\t'show git url'
+--git\t'show git url'
+--npm\t'show npm url'
+--homepage\t'show homepage url'
+--contributions\t'show git contributions url'
+--wiki\t'show git wiki url'
+--issues\t'show git issues url'
+--report\t'show git issues url'
+--discussions\t'show git discussions url'
+--clients-repo\t'show git clients-repo url'
+--sources\t'show useful list of sources'"
+`
+
+const completeCompletions: string = `# fish-lsp complete
+complete -c fish-lsp -n __fish_use_subcommand -a complete -d 'completion utils for fish-lsp cli'
+complete -c fish-lsp -n '__fish_lsp_using_command complete; and not __fish_contains_opt features' -l features -d 'show features'
+complete -c fish-lsp -n '__fish_lsp_using_command complete; and not __fish_contains_opt fish' -l fish -d 'show completion/fish-lsp.fish'
+complete -c fish-lsp -n '__fish_lsp_using_command complete; and not __fish_contains_opt names' -l names -d 'show feature names of completions'
+complete -c fish-lsp -n '__fish_lsp_using_command complete; and not __fish_contains_opt toggle' -l toggle -d 'show feature names of completions'
+`
+
+const loggerCompletions: string = `# fish-lsp logger --
+complete -c fish-lsp -n __fish_use_subcommand -x -a logger -d 'logger utilities'
+complete -c fish-lsp -n '__fish_lsp_using_command logger; and not __fish_contains_opt -s s show' -s s -l show -d 'show the "logs.txt" file'
+complete -c fish-lsp -n '__fish_lsp_using_command logger; and not __fish_contains_opt -s c clear' -s c -l clear -d 'clear the "logs.txt" file'
+complete -c fish-lsp -n '__fish_lsp_using_command logger; and not __fish_contains_opt -s q quiet' -s q -l quiet -d 'only write to "logs.txt" file'
+complete -c fish-lsp -n '__fish_lsp_using_command logger; and not __fish_contains_opt -s d date' -s d -l date -d 'write date to "logs.txt" file'
+complete -c fish-lsp -n '__fish_lsp_using_command logger; and not __fish_contains_opt config' -l config -d 'show the logger config'
+`
+
+const infoCompletions: string = `# fish-lsp info --
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt bin' -l bin -d 'show the binary path'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt repo' -l repo -d 'show the repo path'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt time' -l time -d 'show the build-time'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt env' -l env -d 'show the env-variables used'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt lsp-version' -l lsp-verision -d 'show the npm package for the lsp-verision'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt capabilities' -l capabilities -d 'show the lsp capabilities implemented'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt man-file' -l man-file -d 'show man file path'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt logs-file' -l logs-file -d 'show logs.txt file path'
+complete -c fish-lsp -n '__fish_lsp_using_command info; and not __fish_contains_opt more' -l more -d 'show more info'
+`
+
+
+const mapNames = ConfigMap.configNames.join(' ')
+const featuresCompletions: string = `# print all $fish_lsp_submcommands
+function _fish_lsp_get_features
+ printf %b\\n ${mapNames}
+end
+`
+
// firefox-dev https://github.com/fish-shell/fish-shell/blob/master/share/completions/cjxl.fish
export function buildFishLspCompletions(commandBin: Command) {
const subcmdStrs = commandBin.commands.map(cmd => `${cmd.name()}\\t'${cmd.summary()}'`).join('\n');
const output: string[] = [];
- output.push('# fish-lsp complete --fish > ~/.config/fish/completions/fish-lsp.fish');
- output.push('complete -c fish-lsp -f', '\n');
- output.push('complete -c fish-lsp -n "__fish_use_subcommand" -a "\n' + subcmdStrs + '\"');
- // output.push('complete -c fish-lsp -n "__fish_seen_subcommand_from start" -a "show --enable --disable"');
- output.push('\nset __fish_lsp_subcommands bare min start\n');
- output.push(
- [
- 'complete -c fish-lsp -n \'__fish_seen_subcommand_from $__fish_lsp_subcommands\' -a \"',
- '--dump\\t\'dump output and stop server\'',
- '--enable\\t\'enable feature\'',
- '--disable\\t\'disable feature\'\"',
- '',
- ].join('\n').trimStart(),
- );
- output.push(
- [
- 'complete -c fish-lsp -n "__fish_seen_subcommand_from url" -a \"',
- '--repo\\t\'show git url\'',
- '--git\\t\'show git url\'',
- '--npm\\t\'show npm url\'',
- '--homepage\\t\'show homepage url\'',
- '--contributions\\t\'show git contributions url\'',
- '--wiki\\t\'show git wiki url\'',
- '--issues\\t\'show git issues url\'',
- '--report\\t\'show git issues url\'',
- '--discussions\\t\'show git discussions url\'',
- '--clients-repo\\t\'show git clients-repo url\'',
- '--sources\\t\'show useful list of sources\'\"',
- '',
- ].join('\n').trimStart(),
- );
- output.push(
- [
- 'complete -c fish-lsp -n "__fish_seen_subcommand_from complete" -a \"',
- '--names\\t\'show the feature names of the completions\'',
- '--toggles\\t\'show the feature names of the completions\'',
- '--fish\\t\'show fish script\'',
- '--features\\t\'show features\'\"',
- '',
- ].join('\n').trimStart(),
- );
-
- output.push('set __info_subcommands \'info\'');
+ output.push(AUTO_GENERATED_HEADER_STRING);
+ output.push(__fish_lsp_using_command)
+
+ output.push('# disable file completions');
+ output.push('complete -c fish-lsp -f', '');
+ output.push(`complete -c fish-lsp -n "__fish_use_subcommand" -a "\n${subcmdStrs}\"`);
+
output.push([
- 'complete -c fish-lsp -n "__fish_seen_subcommand_from $__info_subcommands" -a \"',
- '--bin\\t\'show bin path\'',
- '--repo\\t\'show repo path\'',
- '--time\\t\'show build-time\'',
- '--env\\t\'show the env variables used\'',
- '--lsp-version\\t\'show the lsp version\'',
- '--capabilities\\t\'show the lsp capabilities implemented\'',
- '--man-file\\t\'show man file path\'',
- '--logs-file\\t\'show logs.txt file path\'',
- '--more\\t\'show more info\'\"',
+ '',
+ 'set __fish_lsp_subcommands bare min start',
+ '',
+ '# fish_lsp [bare|min|start] -- ',
+ 'complete -c fish-lsp -n \'__fish_seen_subcommand_from $__fish_lsp_subcommands\' -a \"',
+ '--dump\\t\'dump output and stop server\'',
+ '--enable\\t\'enable feature\'',
+ '--disable\\t\'disable feature\'\"',
'',
].join('\n'));
- output.push([
- 'function _fish_lsp_get_features',
- ` printf %b\\n ${ConfigMap.configNames.join(' ')}`,
- 'end',
- ].join('\n'));
- // output.push(' fish-lsp complete --features')
+ output.push(urlCompletions);
+
+ output.push(completeCompletions);
+ output.push(infoCompletions);
+ output.push(loggerCompletions);
+ output.push(featuresCompletions);
output.push('# COMPLETION: fish-lsp subcmd