Skip to content

Commit

Permalink
fix: context on class-based addon api (ember-tooling#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart authored Jun 6, 2020
1 parent e74f11f commit 8d55cd1
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/addon-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function requireUncached(module: string) {
instanceResult.onReference = instance.onReference.bind(instance);
}

return instance;
return instanceResult;
}
} catch (e) {
logError(e);
Expand Down
27 changes: 27 additions & 0 deletions test/__snapshots__/integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,33 @@ Object {
}
`;

exports[`integration Able to use classes for API support dummy class-based addon definition:template with correctly binded context 1`] = `
Object {
"registry": Object {
"component": Object {
"hello": Array [
"app/components/hello/index.hbs",
],
},
},
"response": Array [
Object {
"range": Object {
"end": Object {
"character": 0,
"line": 0,
},
"start": Object {
"character": 0,
"line": 0,
},
},
"uri": "/app/components/hello/index.hbs",
},
],
}
`;

exports[`integration Autocomplete works for broken templates autocomplete information for component #1 {{ 1`] = `
Array [
Object {
Expand Down
74 changes: 74 additions & 0 deletions test/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,80 @@ describe('integration', function () {

expect(result).toMatchSnapshot();
});

it('support dummy class-based addon definition:template with correctly binded context', async () => {
const result = await getResult(
DefinitionRequest.type,
connection,
{
node_modules: {
provider: {
lib: {
'langserver.js': `
module.exports = class Boo {
end() {
return {
character: 0,
line: 0,
};
}
start() {
return {
character: 0,
line: 0,
};
}
onDefinition(root) {
let path = require("path");
let filePath = path.resolve(
path.normalize(
path.join(__dirname, "./../../../app/components/hello/index.hbs")
)
);
return [
{
range: {
end: this.end(),
start: this.start(),
},
uri: filePath,
},
];
}
};
`,
},
'package.json': JSON.stringify({
name: 'provider',
'ember-language-server': {
entry: './lib/langserver',
capabilities: {
definitionProvider: true,
},
},
}),
},
},
'package.json': JSON.stringify({
dependencies: {
provider: '*',
},
}),
app: {
components: {
hello: {
'index.hbs': '{{this}}',
},
},
},
},
'app/components/hello/index.hbs',
{ line: 0, character: 3 }
);

expect(result).toMatchSnapshot();
});
});
describe('Able to provide API:Definition', () => {
it('support dummy addon definition:template', async () => {
Expand Down

0 comments on commit 8d55cd1

Please sign in to comment.