@@ -4,6 +4,8 @@ import { TextDocument } from 'vscode-languageserver-textdocument'
44import { Position } from 'vscode-languageserver'
55import { getTextOnLine } from './TextDocumentUtils'
66
7+ const DOTTED_IDENTIFIER_REGEX = / \b (?: [ a - z A - Z ] [ \w ] * ) (?: \. [ a - z A - Z ] [ \w ] * ) * \b / // Matches a word followed by optional dotted words
8+
79/**
810 * Represents a code expression, either a single identifier or a dotted expression.
911 * For example, "plot" or "pkg.Class.func".
@@ -82,7 +84,6 @@ export function getExpressionAtPosition (textDocument: TextDocument, position: P
8284 * @returns An object containing the string identifier at the position, as well as the column number at which the identifier starts.
8385 */
8486function getIdentifierAtPosition ( textDocument : TextDocument , position : Position ) : { identifier : string , start : number } {
85- const DOTTED_IDENTIFIER_REGEX = / [ \w . ] + /
8687 let lineText = getTextOnLine ( textDocument , position . line )
8788
8889 const result = {
@@ -94,12 +95,19 @@ function getIdentifierAtPosition (textDocument: TextDocument, position: Position
9495 let offset = 0
9596
9697 while ( matchResults != null ) {
97- if ( matchResults . index == null || matchResults . index > position . character ) {
98- // Already passed the cursor - no match found
98+ if ( matchResults . index == null ) {
99+ // No result found
99100 break
100101 }
101102
102103 const startChar = offset + matchResults . index
104+
105+ if ( startChar > position . character ) {
106+ // Passed the cursor - no match found
107+ break
108+ }
109+
110+
103111 if ( startChar + matchResults [ 0 ] . length >= position . character ) {
104112 // Found overlapping identifier
105113 result . identifier = matchResults [ 0 ]
0 commit comments