fish-lsp
Version:
LSP implementation for fish/fish-shell
156 lines (155 loc) • 7.68 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.singleQuoteVariableExpansion = 2001;
ErrorCodes.usedAlias = 2002;
ErrorCodes.usedUnviersalDefinition = 2003;
ErrorCodes.testCommandMissingStringCharacters = 3001;
ErrorCodes.missingQuietOption = 3002;
ErrorCodes.expansionInDefinition = 3003;
ErrorCodes.autoloadedFunctionMissingDefinition = 4001;
ErrorCodes.autoloadedFunctionFilenameMismatch = 4002;
ErrorCodes.functionNameUsingReservedKeyword = 4003;
ErrorCodes.unusedLocalFunction = 4004;
// export const preferAutloadedFunctionHasDescription = 4005;
ErrorCodes.argparseMissingEndStdin = 5001;
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.singleQuoteVariableExpansion]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.singleQuoteVariableExpansion,
codeDescription: { href: 'https://fishshell.com/docs/current/language.html#variable-expansion' },
source: 'fish-lsp',
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.expansionInDefinition]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.expansionInDefinition,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/set.html' },
source: 'fish-lsp',
message: 'Variable definition should not include expansion character',
},
[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.unusedLocalFunction]: {
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
code: ErrorCodes.unusedLocalFunction,
codeDescription: { href: 'https://fishshell.com/docs/current/cmds/functions.html' },
source: 'fish-lsp',
message: 'Unused local function',
},
[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',
},
};
/** All error codes */
ErrorCodes.allErrorCodes = Object.values(ErrorCodes.codes).map((diagnostic) => diagnostic.code);
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 = {}));