Skip to content

Commit

Permalink
JS: Improve completion for property chain (obj.prop1.prop2) with embe…
Browse files Browse the repository at this point in the history
…dded comments and new lines
  • Loading branch information
matthiasblaesing committed Mar 31, 2024
1 parent bb2d43f commit 9766a62
Show file tree
Hide file tree
Showing 36 changed files with 439 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to
int orgTokenSequencePos = tokenSequence.offset();
boolean accept = true;
boolean moreTokens = movePrevious ? tokenSequence.movePrevious() : true;
while((tokenSequence.token().id() == JsTokenId.BLOCK_COMMENT || tokenSequence.token().id() == JsTokenId.LINE_COMMENT)) {
moreTokens = tokenSequence.movePrevious();
if(! moreTokens) {
break;
}
}

for (int i = tokenIdChain.length - 1; i >= 0; i --){
Object tokenID = tokenIdChain[i];
Expand All @@ -328,8 +334,14 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to
}

if (tokenID instanceof JsTokenId) {
if (tokenSequence.token().id() == tokenID){
if (tokenSequence.token().id() == tokenID) {
moreTokens = tokenSequence.movePrevious();
while ((tokenSequence.token().id() == JsTokenId.BLOCK_COMMENT || tokenSequence.token().id() == JsTokenId.LINE_COMMENT)) {
moreTokens = tokenSequence.movePrevious();
if (!moreTokens) {
break;
}
}
} else {
// NO MATCH
accept = false;
Expand All @@ -342,7 +354,7 @@ private static boolean acceptTokenChain(TokenSequence tokenSequence, Object[] to

tokenSequence.move(orgTokenSequencePos);
tokenSequence.moveNext();
return accept;
return accept;
}

private static void balanceBracketBack(TokenSequence<JsTokenId> ts) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

impo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
impo|
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS import [PUBLIC] metaproperties.js
KEYWORD import ECMAScript 6 - 2015
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import.meta.url;
function dummy() {
new.target;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import.|meta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import.me|ta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
import.meta.|url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD resolve(moduleName: String): S [PUBLIC] <font color=#999999>metaproperties.js</font>
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import.meta.ur|l;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
ne|w.target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS new [PUBLIC] metaproperties.js
KEYWORD new null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new.|target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new.targ|et;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import/*dummy*/.meta.url;
function dummy() {
new/*dummy*/.target;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/.|meta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/.me|ta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
import/*dummy*/.meta.|url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD resolve(moduleName: String): S [PUBLIC] <font color=#999999>metaproperties.js</font>
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/.meta.ur|l;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
ne|w/*dummy*/.target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS new [PUBLIC] metaproperties.js
KEYWORD new null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new/*dummy*/.|target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new/*dummy*/.targ|et;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import/*dummy*/./*dummy*/meta.url;
function dummy() {
new/*dummy*/./*dummy*/target;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/.|/*dummy*/meta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/./*dummy*/|meta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/./*dummy*/me|ta.url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS meta [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
import/*dummy*/./*dummy*/meta.|url;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD resolve(moduleName: String): S [PUBLIC] <font color=#999999>metaproperties.js</font>
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
import/*dummy*/./*dummy*/meta.ur|l;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
FIELD url: null|String [PUBLIC] <font color=#999999>metaproperties.js</font>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Code completion result for source line:
ne|w/*dummy*/./*dummy*/target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
CLASS new [PUBLIC] metaproperties.js
KEYWORD new null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new/*dummy*/.|/*dummy*/target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new/*dummy*/./*dummy*/|target;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
new/*dummy*/./*dummy*/targ|et;
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
METHOD target(): undefined [PUBLIC] metaproperties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import(
import
.meta
.resolve("demo")
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<FunctionNode name='import-meta-resolve-multiline.js' kind='MODULE' start='0' end='870'>
<isProgram/>
<!-- FunctionNode Parameters -->
<!-- FunctionNode Body -->
<Block start='0' end='869'>
<isFunctionBody/>
<isSynthetic/>
<!-- Block Statements -->
<ExpressionStatement start='809' end='869'>
<CallNode start='809' end='868'>
<!-- CallNode Arguments -->
<CallNode start='821' end='866'>
<!-- CallNode Arguments -->
<StringLiteralNode value='demo' start='860' end='864'/>
<!-- CallNode Function -->
<AccessNode property='resolve' start='821' end='858'>
<!-- AccessNode Base -->
<AccessNode property='meta' start='821' end='841'>
<!-- AccessNode Base -->
<IdentNode start='821' end='827'>
<name>import</name>
</IdentNode>
</AccessNode>
</AccessNode>
</CallNode>
<!-- CallNode Function -->
<IdentNode start='815' end='815'>
<name>import</name>
</IdentNode>
</CallNode>
</ExpressionStatement>
</Block>
</FunctionNode>
Loading

0 comments on commit 9766a62

Please sign in to comment.