Skip to content

Commit

Permalink
loose mode cannot work with ts codeactions
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Jan 6, 2023
1 parent 622f7e5 commit 1b6e779
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/core/src/language-server/code-action-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 [];
Expand All @@ -56,6 +60,7 @@ export class CodeActionProvider {
context: CodeActionContext
): CodeAction[] {
let errorCodes = this.cleanDiagnosticCode(context.diagnostics);

let { transformedStart, transformedEnd, transformedFileName } = this.getTransformedOffsets(
filePath,
{
Expand Down Expand Up @@ -99,6 +104,7 @@ export class CodeActionProvider {
version,
this.documents.getDocumentContents(filePath)
);

return TextDocumentEdit.create(
OptionalVersionedTextDocumentIdentifier.create(snapshot.uri, version),
change.textChanges.map((edit) => {
Expand Down

0 comments on commit 1b6e779

Please sign in to comment.