@@ -8,6 +8,7 @@ import { showCodeWhispererWebview } from '../vue/backend'
88import { telemetry } from '../../shared/telemetry/telemetry'
99import { PromptSettings } from '../../shared/settings'
1010import { CodeWhispererSource } from './types'
11+ import { Disposable , DocumentSelector , TextDocument , Position , InlayHint , InlayHintsProvider } from 'vscode'
1112/**
1213 * The methods with backend logic for the Codewhisperer Getting Started Page commands.
1314 */
@@ -41,3 +42,89 @@ export class CodeWhispererCommandDeclarations implements CommandDeclarations<Cod
4142 ) ,
4243 } as const
4344}
45+
46+ let hintShown = false
47+
48+ const myInlayHintsProvider : InlayHintsProvider = {
49+ provideInlayHints ( document : TextDocument ) : InlayHint [ ] {
50+ const hints : InlayHint [ ] = [ ]
51+ const editor = vscode . window . activeTextEditor
52+
53+ if ( hintShown || editor === undefined ) {
54+ return hints
55+ }
56+
57+ const position = editor . selection . active
58+ const line = editor . document . lineAt ( position . line )
59+
60+ if ( editor . document . getText ( ) . length === 0 || position . character === line . text . length ) {
61+ // Display hint at the beginning of the file for empty files
62+ hints . push ( {
63+ label : 'CodeWhisperer suggests code as you type or enter a new line, press TAB to accept' ,
64+ position : new Position ( 0 , 0 ) ,
65+ } )
66+ hintShown = true
67+ }
68+ // else {
69+ // if(position.character === line.text.length) {
70+ // // Cursor is at end of line
71+ // //hints.push({ label: 'This file is empty', position: new Position(0, 0) });
72+ // hints.push({ label: 'End of Line', position: editor.selection.active });
73+ // hintShown = true;
74+ // }
75+ // }
76+
77+ return hints
78+ } ,
79+ }
80+
81+ const documentSelector : DocumentSelector = [ '*' ]
82+
83+ const disposables : Disposable = vscode . languages . registerInlayHintsProvider ( documentSelector , myInlayHintsProvider )
84+
85+ let activeEditor = vscode . window . activeTextEditor
86+
87+ vscode . window . onDidChangeActiveTextEditor ( editor => {
88+ activeEditor = editor
89+ } )
90+
91+ vscode . workspace . onDidChangeTextDocument ( event => {
92+ if ( activeEditor && event . document === activeEditor . document ) {
93+ // Clear hints when text changes
94+ disposables . dispose ( )
95+ hintShown = false
96+ }
97+ } )
98+
99+ vscode . extensions . onDidChange ( ( ) => {
100+ disposables . dispose ( )
101+ } )
102+
103+ /** WORKING
104+ * This Hover shows the suggestion for user to write down the comment
105+ */
106+
107+ export class EndOfLineHoverProvider implements vscode . HoverProvider {
108+ provideHover (
109+ document : vscode . TextDocument ,
110+ position : vscode . Position ,
111+ token : vscode . CancellationToken
112+ ) : vscode . Hover {
113+ const line = document . lineAt ( position . line )
114+ if ( position . character === line . text . length || document . getText ( ) . length === 0 ) {
115+ // Cursor at end of line
116+ return new vscode . Hover ( 'CodeWhisperer suggests code as you type or enter a new line, press TAB to accept' )
117+ }
118+ return new vscode . Hover ( '' )
119+ }
120+ }
121+
122+ //Register this in extension
123+
124+ const provider = new EndOfLineHoverProvider ( )
125+
126+ const disposable : Disposable = vscode . languages . registerHoverProvider ( { language : '*' } , provider )
127+
128+ vscode . extensions . onDidChange ( ( ) => {
129+ disposable . dispose ( )
130+ } )
0 commit comments