fish-lsp
Version:
LSP implementation for fish/fish-shell
221 lines (220 loc) • 11.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorCodes = void 0;
const vscode_languageserver_1 = require("vscode-languageserver");
var ErrorCodes;
(function (ErrorCodes) {
ErrorCodes.missingEnd = 1001;
ErrorCodes.extraEnd = 1002;
ErrorCodes.zeroIndexedArray = 1003;
ErrorCodes.sourceFileDoesNotExist = 1004;
ErrorCodes.dotSourceCommand = 1005;
ErrorCodes.singleQuoteVariableExpansion = 2001;
ErrorCodes.usedAlias = 2002;
ErrorCodes.usedUnviersalDefinition = 2003;
ErrorCodes.testCommandMissingStringCharacters = 3001;
ErrorCodes.missingQuietOption = 3002;
ErrorCodes.dereferencedDefinition = 3003;
ErrorCodes.autoloadedFunctionMissingDefinition = 4001;
ErrorCodes.autoloadedFunctionFilenameMismatch = 4002;
ErrorCodes.functionNameUsingReservedKeyword = 4003;
ErrorCodes.unusedLocalDefinition = 4004;
ErrorCodes.autoloadedCompletionMissingCommandName = 4005;
ErrorCodes.duplicateFunctionDefinitionInSameScope = 4006;
ErrorCodes.autoloadedFunctionWithEventHookUnused = 4007;
ErrorCodes.argparseMissingEndStdin = 5001;
ErrorCodes.unreachableCode = 5555;
ErrorCodes.fishLspDeprecatedEnvName = 6001;
ErrorCodes.invalidDiagnosticCode = 8001;
ErrorCodes.syntaxError = 9999;
ErrorCodes.codes = {
[ErrorCodes.missingEnd]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.missingEnd,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/end.html' },
source: 'fish-lsp',
message: 'missing closing token',
},
[ErrorCodes.extraEnd]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.extraEnd,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/end.html' },
source: 'fish-lsp',
message: 'extra closing token',
},
[ErrorCodes.zeroIndexedArray]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.zeroIndexedArray,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#slices' },
source: 'fish-lsp',
message: 'invalid array index',
},
[ErrorCodes.sourceFileDoesNotExist]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.sourceFileDoesNotExist,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/source.html' },
source: 'fish-lsp',
message: 'source filename does not exist',
},
[ErrorCodes.dotSourceCommand]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.dotSourceCommand,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/source.html' },
source: 'fish-lsp',
message: '`.` source command not allowed, use `source` instead',
},
[ErrorCodes.singleQuoteVariableExpansion]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.singleQuoteVariableExpansion,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#variable-expansion' },
source: 'fish-lsp',
isDeprecated: true,
message: 'non-escaped expansion variable in single quote string',
},
[ErrorCodes.usedAlias]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.usedAlias,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/alias.html' },
source: 'fish-lsp',
message: 'alias used, prefer using functions instead',
},
[ErrorCodes.usedUnviersalDefinition]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.usedUnviersalDefinition,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#universal-variables' },
source: 'fish-lsp',
message: 'Universal scope set in non-interactive session',
},
[ErrorCodes.testCommandMissingStringCharacters]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.testCommandMissingStringCharacters,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/test.html#examples' },
source: 'fish-lsp',
message: 'test command string check, should be wrapped as a string',
},
[ErrorCodes.missingQuietOption]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.missingQuietOption,
codeDescription: { href: 'https://fishshell.com/docs/current/search.html?q=-q' },
source: 'fish-lsp',
message: 'Conditional command should include a silence option',
},
[ErrorCodes.dereferencedDefinition]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.dereferencedDefinition,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#dereferencing-variables' },
source: 'fish-lsp',
message: 'Dereferenced variable could be undefined',
},
[ErrorCodes.autoloadedFunctionMissingDefinition]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.autoloadedFunctionMissingDefinition,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/functions.html' },
source: 'fish-lsp',
message: 'Autoloaded function missing definition',
},
[ErrorCodes.autoloadedFunctionFilenameMismatch]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.autoloadedFunctionFilenameMismatch,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/functions.html' },
source: 'fish-lsp',
message: 'Autoloaded filename does not match function name',
},
[ErrorCodes.functionNameUsingReservedKeyword]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.functionNameUsingReservedKeyword,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/functions.html' },
source: 'fish-lsp',
message: 'Function name uses reserved keyword',
},
[ErrorCodes.unusedLocalDefinition]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.unusedLocalDefinition,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#local-variables' },
source: 'fish-lsp',
message: 'Unused local',
},
[ErrorCodes.autoloadedCompletionMissingCommandName]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.autoloadedCompletionMissingCommandName,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/complete.html' },
source: 'fish-lsp',
message: 'Autoloaded completion missing command name',
},
[ErrorCodes.duplicateFunctionDefinitionInSameScope]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.duplicateFunctionDefinitionInSameScope,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/functions.html' },
source: 'fish-lsp',
message: 'Duplicate function definition exists in the same scope.\n\nAmbiguous function',
},
[ErrorCodes.autoloadedFunctionWithEventHookUnused]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.autoloadedFunctionWithEventHookUnused,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#event' },
source: 'fish-lsp',
message: 'Autoloaded function with event hook is unused',
},
[ErrorCodes.argparseMissingEndStdin]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.argparseMissingEndStdin,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/argparse.html' },
source: 'fish-lsp',
message: 'argparse missing end of stdin',
},
[ErrorCodes.unreachableCode]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.unreachableCode,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#unreachable-code-blocks' },
source: 'fish-lsp',
message: 'Unreachable code blocks detected',
},
[ErrorCodes.fishLspDeprecatedEnvName]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.fishLspDeprecatedEnvName,
codeDescription: { href: 'https://github.com/ndonfris/fish-lsp#environment-variables' },
source: 'fish-lsp',
message: 'Deprecated fish-lsp environment variable name',
},
[ErrorCodes.invalidDiagnosticCode]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.invalidDiagnosticCode,
codeDescription: { href: 'https://github.com/ndonfris/fish-lsp/wiki/Diagnostic-Error-Codes' },
source: 'fish-lsp',
message: 'Invalid diagnostic control code',
},
[ErrorCodes.syntaxError]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Error,
code: ErrorCodes.syntaxError,
codeDescription: { href: 'https://fishshell.com/docs/current/fish_for_bash_users.html#syntax-overview' },
source: 'fish-lsp',
message: 'fish syntax error',
},
};
ErrorCodes.allErrorCodes = Object.values(ErrorCodes.codes).map((diagnostic) => diagnostic.code);
ErrorCodes.allErrorCodeObjects = Object.values(ErrorCodes.codes);
ErrorCodes.nonDeprecatedErrorCodes = ErrorCodes.allErrorCodeObjects.filter((code) => !code.isDeprecated);
function getSeverityString(severity) {
if (!severity)
return '';
switch (severity) {
case vscode_languageserver_1.DiagnosticSeverity.Error:
return 'Error';
case vscode_languageserver_1.DiagnosticSeverity.Warning:
return 'Warning';
case vscode_languageserver_1.DiagnosticSeverity.Information:
return 'Information';
case vscode_languageserver_1.DiagnosticSeverity.Hint:
return 'Hint';
default:
return '';
}
}
ErrorCodes.getSeverityString = getSeverityString;
function getDiagnostic(code) {
if (typeof code === 'number')
return ErrorCodes.codes[code];
return ErrorCodes.codes[code];
}
ErrorCodes.getDiagnostic = getDiagnostic;
})(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {}));