@@ -31,7 +31,7 @@ export class LspCompletionProviderAddon extends Disposable implements ITerminalA
31
31
this . _provider = provider ;
32
32
this . _textVirtualModel = textVirtualModel ;
33
33
this . _lspTerminalModelContentProvider = lspTerminalModelContentProvider ;
34
- this . triggerCharacters = provider . triggerCharacters ? [ ...provider . triggerCharacters , ' ' ] : [ ' ' ] ;
34
+ this . triggerCharacters = provider . triggerCharacters ? [ ...provider . triggerCharacters , ' ' , '(' ] : [ ' ' , '( '] ;
35
35
}
36
36
37
37
activate ( terminal : Terminal ) : void {
@@ -83,34 +83,47 @@ export class LspCompletionProviderAddon extends Disposable implements ITerminalA
83
83
}
84
84
}
85
85
86
- export function createCompletionItemPython ( cursorPosition : number , prefix : string , kind : TerminalCompletionItemKind , label : string | CompletionItemLabel , detail : string | undefined ) : TerminalCompletionItem {
87
- const endsWithDot = prefix . endsWith ( '.' ) ;
88
- const endsWithSpace = prefix . endsWith ( ' ' ) ;
89
-
90
- if ( endsWithSpace ) {
91
- // Case where user is triggering completion with space:
92
- // For example, typing `import ` to request completion for list of modules
93
- // This is similar to completions we are used to seeing in upstream shell (such as typing `ls ` inside bash).
94
- const lastWord = endsWithSpace ? '' : prefix . split ( ' ' ) . at ( - 1 ) ?? '' ;
95
- return {
96
- label : label ,
97
- detail : detail ?? detail ?? '' ,
98
- replacementIndex : cursorPosition - lastWord . length ,
99
- replacementLength : lastWord . length ,
100
- kind : kind ?? kind ?? TerminalCompletionItemKind . Method
101
- } ;
102
- } else {
103
- // Case where user is triggering completion with dot:
104
- // For example, typing `pathlib.` to request completion for list of methods, attributes from the pathlib module.
105
- const lastWord = endsWithDot ? '' : prefix . split ( '.' ) . at ( - 1 ) ?? '' ;
106
- return {
107
- label,
108
- detail : detail ?? detail ?? '' ,
109
- replacementIndex : cursorPosition - lastWord . length ,
110
- replacementLength : lastWord . length ,
111
- kind : kind ?? kind ?? TerminalCompletionItemKind . Method
112
- } ;
86
+ export function createCompletionItemPython (
87
+ cursorPosition : number ,
88
+ prefix : string ,
89
+ kind : TerminalCompletionItemKind ,
90
+ label : string | CompletionItemLabel ,
91
+ detail : string | undefined
92
+ ) : TerminalCompletionItem {
93
+ const lastWord = getLastWord ( prefix ) ;
94
+
95
+ return {
96
+ label,
97
+ detail : detail ?? '' ,
98
+ replacementIndex : cursorPosition - lastWord . length ,
99
+ replacementLength : lastWord . length ,
100
+ kind : kind ?? TerminalCompletionItemKind . Method
101
+ } ;
102
+ }
103
+
104
+ function getLastWord ( prefix : string ) : string {
105
+ if ( prefix . endsWith ( ' ' ) ) {
106
+ return '' ;
113
107
}
108
+
109
+ if ( prefix . endsWith ( '.' ) ) {
110
+ return '' ;
111
+ }
112
+
113
+ const lastSpaceIndex = prefix . lastIndexOf ( ' ' ) ;
114
+ const lastDotIndex = prefix . lastIndexOf ( '.' ) ;
115
+ const lastParenIndex = prefix . lastIndexOf ( '(' ) ;
116
+
117
+ // Get the maximum index (most recent delimiter)
118
+ const lastDelimiterIndex = Math . max ( lastSpaceIndex , lastDotIndex , lastParenIndex ) ;
119
+
120
+ // If no delimiter found, return the entire prefix
121
+ if ( lastDelimiterIndex === - 1 ) {
122
+ return prefix ;
123
+ }
124
+
125
+ // Return the substring after the last delimiter
126
+ return prefix . substring ( lastDelimiterIndex + 1 ) ;
114
127
}
115
128
116
129
export interface TerminalCompletionItem {
0 commit comments