Skip to content

Commit 22ea66a

Browse files
committed
fixed maybe operator related issues
1 parent 3ba4e9c commit 22ea66a

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

server/src/lexer.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ParamInfo {
2626
method?: boolean
2727
data?: string[]
2828
name?: string
29+
is_call?: boolean
2930
}
3031

3132
export interface CallSite extends AhkSymbol {
@@ -1618,15 +1619,15 @@ export class Lexer {
16181619
if (tk.content as string === '=>') {
16191620
_parent = tn = FuncNode.create(_low, SymbolKind.Function,
16201621
make_range(lk.offset, parser_pos - lk.offset), make_range(lk.offset, lk.length), [...par]);
1621-
mode = BlockType.Method, tn.returns = [parser_pos, 0];
1622+
mode = BlockType.Method, tn.returns = [parser_pos, 0], tn.has_this_param = true;
16221623
tn.parent = prop, tn.children = parse_line(undefined, 'return', 1);
16231624
tn.range.end = document.positionAt(tn.returns[1] = lk.offset + lk.length);
16241625
mode = BlockType.Class, _parent = _cls, tk.fat_arrow_end = true;
16251626
_this.addFoldingRangePos(tn.range.start, tn.range.end, 'line');
16261627
if (_low === 'set')
16271628
tn.params.unshift(HIDDEN_PARAMS.value);
16281629
else prop.returns = tn.returns;
1629-
tn.has_this_param = true, adddeclaration(tn);
1630+
adddeclaration(tn);
16301631
line_ranges.push([tn.range.end.line, nk.offset]);
16311632
} else if (tk.content === '{') {
16321633
tn = FuncNode.create(_low, SymbolKind.Function,
@@ -1679,11 +1680,12 @@ export class Lexer {
16791680
let tn: FuncNode;
16801681
mode = BlockType.Method, _parent = tn = FuncNode.create('get', SymbolKind.Function,
16811682
rg = make_range(off, parser_pos - off), ZERO_RANGE, par);
1683+
tn.has_this_param = true;
16821684
tn.parent = prop, prop.get = tn, prop.returns = tn.returns = [parser_pos, 0];
16831685
tn.children = parse_line(undefined, 'return', 1), mode = BlockType.Class, _parent = _cls;
16841686
prop.range.end = tn.range.end = document.positionAt(tn.returns[1] = lk.offset + lk.length);
16851687
_this.addFoldingRangePos(tn.range.start, tn.range.end, 'line');
1686-
tn.has_this_param = tk.fat_arrow_end = true, adddeclaration(tn);
1688+
tk.fat_arrow_end = true, adddeclaration(tn);
16871689
line_ranges.push([prop.range.end.line, oo]);
16881690
fc.semantic.modifier! |= SemanticTokenModifiers.readonly;
16891691
}
@@ -3599,9 +3601,9 @@ export class Lexer {
35993601
mode |= BlockType.Pair;
36003602
const t = _pk.previous_token;
36013603
_pk.paraminfo = paraminfo;
3602-
if (paraminfo.name || !_pk.topofline && t && _pk.prefix_is_whitespace === undefined
3603-
&& ((t.previous_pair_pos ?? t.in_expr) !== undefined || t.type === TokenType.Identifier || t.type === TokenType.Dot))
3604-
iscall = true;
3604+
if (paraminfo.name || t && _pk.topofline < 1 &&
3605+
(b === '[' || _pk.prefix_is_whitespace === undefined) && isYieldsOperand(t))
3606+
paraminfo.is_call = iscall = true;
36053607
} else _pk.op_type = -1;
36063608
while (nexttoken()) {
36073609
if (tk.topofline) {
@@ -5493,14 +5495,18 @@ export class Lexer {
54935495
c += input[parser_pos++], i = m;
54945496

54955497
if (c === '?') {
5496-
lst = createToken(c, TokenType.Operator, offset, 1, bg);
5497-
const bak = parser_pos, tk = lst, t = get_token_ignore_comment(depth + 1);
5498-
parser_pos = bak;
5499-
if (t.type === TokenType.Reserved ? (t.topofline && LINE_STARTERS.includes(t.content.toLowerCase())) :
5500-
(')]},:??'.includes(t.content) || t.content === '.' && t.type !== TokenType.Operator)) {
5501-
tk.ignore = true;
5502-
if (t.content === '.' && ahkVersion < alpha_3 - 1)
5503-
_this.addDiagnostic(diagnostic.requireVerN(alpha_3 - 1), tk.offset, tk.length, { code: DiagnosticCode.opt_chain });
5498+
const pt = lst, tk = lst = createToken(c, TokenType.Operator, offset, 1, bg);
5499+
if (pt.type === TokenType.Identifier || (pt.type === TokenType.BracketEnd ?
5500+
_this.tokens[pt.previous_pair_pos!]?.paraminfo?.is_call :
5501+
pt.op_type === 1 && pt.content === '%')) {
5502+
const bak = parser_pos, t = get_token_ignore_comment(depth + 1);
5503+
parser_pos = bak;
5504+
if (t.type === TokenType.Reserved ? (t.topofline && LINE_STARTERS.includes(t.content.toLowerCase())) :
5505+
(')]},:??'.includes(t.content) || t.content === '.' && t.type !== TokenType.Operator)) {
5506+
tk.ignore = true;
5507+
if (t.content === '.' && ahkVersion < alpha_3 - 1)
5508+
_this.addDiagnostic(diagnostic.requireVerN(alpha_3 - 1), tk.offset, tk.length, { code: DiagnosticCode.opt_chain });
5509+
}
55045510
}
55055511
return lst = tk;
55065512
} else if (c === '??=' && ahkVersion < alpha_3 - 1)
@@ -8170,8 +8176,10 @@ export function isContinuousLine(lk: Token, tk: Token, parent?: AhkSymbol): bool
81708176
return true;
81718177
case TokenType.Operator:
81728178
return !/^(!|~|not|%|\+\+|--)$/i.test(tk.content) && (
8173-
!(parent as FuncNode)?.has_this_param || !allIdentifierChar.test(tk.content) ||
8174-
parent!.returns?.[1] !== 0 || parent!.kind === SymbolKind.Function);
8179+
!(parent as FuncNode)?.has_this_param || !allIdentifierChar.test(tk.content) || !(
8180+
(parent as FuncNode).ranges || parent!.returns?.[1] === 0 &&
8181+
(parent!.kind !== SymbolKind.Function || parent!.selectionRange === ZERO_RANGE)
8182+
));
81758183
// case TokenType.END_BLOCK:
81768184
// case TokenType.END_EXPR:
81778185
// return false;

syntaxes/ahk2.tmLanguage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@
17201720
"name": "comment.line.ahk2"
17211721
}
17221722
},
1723-
"end": "(?!([*/<>?:=.]+|[+\\-]=?|!==?|,|\\b(?i:(and|contain|not|in|is|or))))[ \t]*([ \t];.*)?(?=\\n)|(?<=^[ \t]*(?i:class|static|if|try|loop|while)[ \t]+\\w+)",
1723+
"end": "(?!([*/<>?:=.]+|[+\\-]=?|!==?|,|\\b(?i:(and|contain|not|in|is|or))))[ \t]*([ \t];.*)?(?=\\n)|(?=^[ \t]*(?i:static|if|try|loop|while)[ \t(])",
17241724
"endCaptures": {
17251725
"3": {
17261726
"name": "comment.line.ahk2"

0 commit comments

Comments
 (0)