X-Git-Url: https://git.josue.xyz/?p=dotfiles%2F.git;a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-eslint%2Fserver%2Findex.ts;h=d4ea81ee8fe1414ecf3ea8a0903f5b56631383ad;hp=a2490381815c8fbc49b26e94efa92a26ab5f6d41;hb=4d07c77cf4d78cab8639e13ddc3c22495e585b0b;hpb=b3950616b54221c40a7dab9099bda675007e5b6e diff --git a/.config/coc/extensions/node_modules/coc-eslint/server/index.ts b/.config/coc/extensions/node_modules/coc-eslint/server/index.ts index a2490381..d4ea81ee 100644 --- a/.config/coc/extensions/node_modules/coc-eslint/server/index.ts +++ b/.config/coc/extensions/node_modules/coc-eslint/server/index.ts @@ -9,7 +9,7 @@ import * as path from 'path' import { Position, CancellationToken, CodeAction, CodeActionKind, CodeActionRequest, Command, createConnection, Diagnostic, DiagnosticSeverity, DidChangeConfigurationNotification, DidChangeWatchedFilesNotification, ErrorCodes, ExecuteCommandRequest, Files, IConnection, NotificationHandler, NotificationType, Range, RequestHandler, RequestType, ResponseError, TextDocumentIdentifier, TextDocuments, TextDocumentSaveReason, TextDocumentSyncKind, TextEdit, VersionedTextDocumentIdentifier, WorkspaceChange } from 'vscode-languageserver' import { URI } from 'vscode-uri' import { CLIOptions, ESLintAutoFixEdit, ESLintError, ESLintModule, ESLintProblem, ESLintReport, Is, TextDocumentSettings } from './types' -import { getAllFixEdits, executeInWorkspaceDirectory, getFilePath, isUNC, resolveModule } from './util' +import { getAllFixEdits, executeInWorkspaceDirectory, getFilePath, isUNC } from './util' import { TextDocument } from 'vscode-languageserver-textdocument' declare var __webpack_require__: any declare var __non_webpack_require__: any @@ -302,7 +302,7 @@ function resolveSettings( resultPromise = connection.workspace .getConfiguration({ scopeUri: uri, section: '' }) .then((settings: TextDocumentSettings) => { - let nodePath: string + let nodePath: string | undefined if (settings.nodePath) { nodePath = settings.nodePath if (nodePath.startsWith('~')) { @@ -311,11 +311,15 @@ function resolveSettings( if (!path.isAbsolute(nodePath)) { nodePath = path.join(URI.parse(settings.workspaceFolder.uri).fsPath, nodePath) } - } else if (settings.packageManager === 'npm') { - nodePath = globalNpmPath() + } + + let resolvedGlobalPackageManagerPath: string | undefined + if (settings.packageManager === 'npm') { + resolvedGlobalPackageManagerPath = globalNpmPath() } else if (settings.packageManager === 'yarn') { - nodePath = globalYarnPath() + resolvedGlobalPackageManagerPath = globalYarnPath() } + let uri = URI.parse(document.uri) let promise: Thenable let directory: string @@ -324,9 +328,15 @@ function resolveSettings( } else { directory = settings.workspaceFolder ? URI.parse(settings.workspaceFolder.uri).fsPath : undefined } - promise = resolveModule('./eslint', directory, nodePath).catch(() => { - return resolveModule('eslint', directory, nodePath) - }) + + if (nodePath !== undefined) { + promise = Files.resolve('eslint', nodePath, nodePath, trace).then(undefined, () => { + return Files.resolve('eslint', resolvedGlobalPackageManagerPath, directory, trace); + }); + } else { + promise = Files.resolve('eslint', resolvedGlobalPackageManagerPath, directory, trace); + } + return promise.then(path => { let library = path2Library.get(path) if (!library) { @@ -351,8 +361,7 @@ function resolveSettings( source: { uri: document.uri } }) return settings - } - ) + }) }) document2Settings.set(uri, resultPromise) return resultPromise @@ -1046,7 +1055,11 @@ class Fixes { public getAllSorted(): FixableProblem[] { let result: FixableProblem[] = [] - this.edits.forEach(value => result.push(value)) + this.edits.forEach(value => { + if (value.edit != null) { + result.push(value) + } + }) return result.sort((a, b) => { let d = a.edit.range[0] - b.edit.range[0] if (d !== 0) { @@ -1110,7 +1123,10 @@ messageQueue.registerRequest( } function createDisableFileTextEdit(editInfo: FixableProblem): TextEdit { - return TextEdit.insert(Position.create(0, 0), `/* eslint-disable ${editInfo.ruleId} */\n`) + // If firts line contains a shebang, insert on the next line instead. + const shebang = textDocument?.getText(Range.create(Position.create(0, 0), Position.create(0, 2))) + const line = shebang === '#!' ? 1 : 0 + return TextEdit.insert(Position.create(line, 0), `/* eslint-disable ${editInfo.ruleId} */\n`) } function getLastEdit(array: FixableProblem[]): FixableProblem { @@ -1127,15 +1143,17 @@ messageQueue.registerRequest( let ruleId = editInfo.ruleId allFixableRuleIds.push(ruleId) - if (!!editInfo.edit) { + if (editInfo.edit != null) { let workspaceChange = new WorkspaceChange() workspaceChange.getTextEditChange({ uri, version: documentVersion }).add(createTextEdit(editInfo)) commands.set(`${CommandIds.applySingleFix}:${ruleId}`, workspaceChange) - result.get(ruleId).fixes.push(CodeAction.create( + let action = CodeAction.create( editInfo.label, Command.create(editInfo.label, CommandIds.applySingleFix, ruleId), CodeActionKind.QuickFix - )) + ) + action.isPreferred = true + result.get(ruleId).fixes.push(action) } if (settings.codeAction.disableRuleComment.enable) {