Skip to content

Commit

Permalink
🐛 Fix showing unuseful code actions for vectors
Browse files Browse the repository at this point in the history
Fix #438.
  • Loading branch information
SPGoding committed May 2, 2020
1 parent fb8ef0c commit aed15c5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions contributors/.all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@
{ "type": "bug", "link": "issues/385", "text": "#385" }
]
},
{
"name": "missinggo",
"avatar_url": "https://www.mcbbs.net/uc_server/avatar.php?uid=2905154&size=middle",
"profile": "https://www.mcbbs.net/home.php?mod=space&uid=2905154",
"contributions": [],
"details": [
{ "type": "bug", "link": "issues/438", "text": "#438" }
]
},
{
"name": "ncfumction",
"avatar_url": "https://cdn.discordapp.com/avatars/416799672674418710/d6b90e26cf0f2be0aeaa321916311db2.png?size=256",
Expand Down
3 changes: 3 additions & 0 deletions contributors/2.0.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ A big _thank you_ goes to these wonderful people! (sorted by the Unicode of name
<td align="center"><a href="https://github.com/mathaym25"><img src="https://avatars2.githubusercontent.com/u/35702771?s=460&u=393d01acff13df6e83beb953bd6f916f514f5141&v=4" width="64px;" alt=""/><br /><sub><b>mathaym25</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/382" target="_blank" title="Ideas, Planning, and Feedback">✨ #382</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/385" target="_blank" title="Bug reports">🐛 #385</a></td>
</tr>
<tr>
<td align="center"><a href="https://www.mcbbs.net/home.php?mod=space&uid=2905154"><img src="https://www.mcbbs.net/uc_server/avatar.php?uid=2905154&size=middle" width="64px;" alt=""/><br /><sub><b>missinggo</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/438" target="_blank" title="Bug reports">🐛 #438</a></td>
<td align="center"><a href=""><img src="https://cdn.discordapp.com/avatars/416799672674418710/d6b90e26cf0f2be0aeaa321916311db2.png?size=256" width="64px;" alt=""/><br /><sub><b>ncfumction</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/376" target="_blank" title="Bug reports">🐛 #376</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/392" target="_blank" title="Bug reports">🐛 #392</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/393" target="_blank" title="Ideas, Planning, and Feedback">✨ #393</a></td>
</tr>
<tr>
<td align="center"><a href="https://afdian.net/@LTCat"><img src="https://pic1.afdiancdn.com/user/df2dfad2960911e89c5252540025c377/avatar/31c78ee63d5dce8ac4848c837fb04204_w160_h160_s35.jpg?imageView2/1/w/240/h/240" width="64px;" alt=""/><br /><sub><b>龙腾猫跃</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/blob/master/CONTRIBUTING.md" target="_blank" title="Financial support">☕ Donate coffee</a></td>
</tr>
</table>
Expand Down
11 changes: 11 additions & 0 deletions src/test/types/nodes/VectorNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,16 @@ describe('VectorNode Tests', () => {
const actual = node[GetCodeActions](uri, info, lineNumber, range, {})
assert.deepStrictEqual(actual, [])
})
it('Should not return align actions when the vector is not of type absolute', () => {
const range = { start: 1, end: 2 }
const node = $(new VectorNode(), {
length: 3,
0: new VectorElementNode(VectorElementType.Relative, 1, '1'),
1: new VectorElementNode(VectorElementType.Relative, 1, '1'),
2: new VectorElementNode(VectorElementType.Relative, 1.4, '1.4'),
})
const actual = node[GetCodeActions](uri, info, lineNumber, range, {})
assert.deepStrictEqual(actual, [])
})
})
})
4 changes: 3 additions & 1 deletion src/types/nodes/VectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export default class VectorNode extends ArgumentNode implements ArrayLike<Vector

[GetCodeActions](uri: string, info: FunctionInfo, lineNumber: number, range: TextRange, diagnostics: DiagnosticMap) {
const ans = super[GetCodeActions](uri, info, lineNumber, range, diagnostics)
if (Array.prototype.some.call(this, (v: VectorElementNode) => !v.raw.includes('.'))) {
if (Array.prototype.some.call(this,
(v: VectorElementNode) => v.type === VectorElementType.Absolute && !v.raw.includes('.')
)) {
ans.push(
getCodeAction(
'vector-align-0.0', [], uri, info.version, lineNumber, this[NodeRange],
Expand Down

0 comments on commit aed15c5

Please sign in to comment.