Skip to content

Commit

Permalink
attempt to get autofixes working
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Feb 5, 2022
1 parent a57aeb8 commit c9cdd7e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/builtin-addons/core/code-actions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { searchAndExtractHbs } from '@lifeart/ember-extract-inline-templates';
import { parseScriptFile } from 'ember-meta-explorer';
import { toPosition } from '../../../estree-utils';
import ASTPath from '../../../glimmer-utils';
import { getFileRanges, RangeWalker } from '../../../utils/glimmer-script';
import { toHbsSource } from '../../../utils/diagnostic';
export interface INodeSelectionInfo {
selection: string | undefined;
location: SourceLocation;
Expand Down Expand Up @@ -42,7 +44,7 @@ function findValidNodeSelection(focusPath: ASTPath): null | INodeSelectionInfo {
return null;
}

const extensionsToLint: string[] = ['.hbs', '.js', '.ts'];
const extensionsToLint: string[] = ['.hbs', '.js', '.ts', '.gts', 'gjs'];

export default class BaseCodeActionProvider implements AddonAPI {
public server!: Server;
Expand All @@ -62,6 +64,27 @@ export default class BaseCodeActionProvider implements AddonAPI {

if (extension === '.hbs') {
ast = this.server.templateCompletionProvider.getAST(documentContent);
} else if (extension === '.gjs' || extension === '.gts') {
const ranges = getFileRanges(documentContent);

const rangeWalker = new RangeWalker(ranges);
const templates = rangeWalker.templates();

if (!templates.length) {
return null;
}

const t = templates[0];

const source = toHbsSource({
startLine: t.loc.start.line,
startColumn: t.loc.start.character,
endColumn: t.loc.end.character,
endLine: t.loc.end.line,
template: t.content,
});

ast = this.server.templateCompletionProvider.getAST(source);
} else {
const templateData = searchAndExtractHbs(documentContent, {
parse(source: string) {
Expand Down

0 comments on commit c9cdd7e

Please sign in to comment.