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 11, 2023
1 parent 622f7e5 commit ab589c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/common/document-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type Document = {
*/
export default class DocumentCache {
private readonly documents = new Map<string, Document>();
// private readonly snapshots = new Map<string, DocumentSnapshot>();

private readonly ts: typeof import('typescript');

private openFileNames: Set<string> = new Set();
Expand Down
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
4 changes: 1 addition & 3 deletions test-packages/js-glimmerx-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
<p>You have clicked the button {{this.count}} times.</p>
<button {{on "click" this.increment}}>Click</button>
`;
Expand Down

0 comments on commit ab589c9

Please sign in to comment.