From ab589c98b11ae6047078f14a5886a6693d5cd3fe Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Fri, 6 Jan 2023 17:14:49 -0500 Subject: [PATCH] loose mode cannot work with ts codeactions --- packages/core/src/common/document-cache.ts | 2 +- .../core/src/language-server/code-action-provider.ts | 12 +++++++++--- test-packages/js-glimmerx-app/src/App.js | 4 +--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/src/common/document-cache.ts b/packages/core/src/common/document-cache.ts index 4ccb8ce0..1b505988 100644 --- a/packages/core/src/common/document-cache.ts +++ b/packages/core/src/common/document-cache.ts @@ -33,7 +33,7 @@ export type Document = { */ export default class DocumentCache { private readonly documents = new Map(); - // private readonly snapshots = new Map(); + private readonly ts: typeof import('typescript'); private openFileNames: Set = new Set(); diff --git a/packages/core/src/language-server/code-action-provider.ts b/packages/core/src/language-server/code-action-provider.ts index 6af10396..ef92620c 100644 --- a/packages/core/src/language-server/code-action-provider.ts +++ b/packages/core/src/language-server/code-action-provider.ts @@ -16,8 +16,10 @@ import type DocumentCache from '../common/document-cache.js'; import type TransformManager from '../common/transform-manager.js'; import type { GetTransformedOffsets } from './glint-language-server.js'; import { offsetToPosition, uriToFilePath } from './util/index.js'; +import { extname } from 'node:path'; // Maps from LSP codeaction API and TS LS CodeAction API +// Does not work with loose mode for the time being export class CodeActionProvider { private documents: DocumentCache; private transformManager: TransformManager; @@ -39,12 +41,14 @@ export class CodeActionProvider { this.getTransformedOffsets = getTransformedOffsets; } - public getCodeActions(document: string, range: Range, context: CodeActionContext): CodeAction[] { + public getCodeActions(filePath: string, range: Range, context: CodeActionContext): CodeAction[] { + const ext = extname(filePath); if ( context.diagnostics.length && - (!context.only || context.only.includes(CodeActionKind.QuickFix)) + (!context.only || context.only.includes(CodeActionKind.QuickFix)) && + ext !== '.hbs' // companion files do not map correctly ) { - return this.applyCodeAction(document, range, context); + return this.applyCodeAction(filePath, range, context); } return []; @@ -56,6 +60,7 @@ export class CodeActionProvider { context: CodeActionContext ): CodeAction[] { let errorCodes = this.cleanDiagnosticCode(context.diagnostics); + let { transformedStart, transformedEnd, transformedFileName } = this.getTransformedOffsets( filePath, { @@ -99,6 +104,7 @@ export class CodeActionProvider { version, this.documents.getDocumentContents(filePath) ); + return TextDocumentEdit.create( OptionalVersionedTextDocumentIdentifier.create(snapshot.uri, version), change.textChanges.map((edit) => { diff --git a/test-packages/js-glimmerx-app/src/App.js b/test-packages/js-glimmerx-app/src/App.js index 158a2956..ceb17211 100644 --- a/test-packages/js-glimmerx-app/src/App.js +++ b/test-packages/js-glimmerx-app/src/App.js @@ -61,11 +61,9 @@ class IncrementableButton extends Component { /** @type {number} the incrementable count */ @tracked count = this.args.startCount; - @action increment() { - } + @action increment() {} static template = hbs` - {{this.foo}}

You have clicked the button {{this.count}} times.

`;