microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.23k stars 29.29k forks source link

vscode.InlineCompletionItemProvider show text at current cursor position and Accept word/Accept line does not work on mac and for windows on latest vscode version #209424

Open ajaygera opened 7 months ago

ajaygera commented 7 months ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce: 1) In vscode editor (for our extension), we need to show some text on user action (lets say on clicking some context menu). After displaying the text, User can insert entire text or insert the text word by word or line by line. The text which needs to be displayed and inserted would be fetched on clicking context menu and can be passed to vscode provider. 2) We need to show the text in new line after the end of the statement rather than at current cursor position In order to achieve both requirements we have used vscode.InlineCompletionItemProvider. i have found vscode.InlineCompletionItemProvider does not fulfill both requirements completely and we are facing below issues 1)Accept word and Accept Line does not work on Windows for vscode version later than 1.86.2. On vscode version later than 1.86.2, On clicking Accept word only first word gets inserted and after that inline suggest toolbar gets disappears. 2)Accept word and Accept Line does not work on mac for any vscode version. On clicking Accept word only first word gets inserted and after that inline suggest toolbar gets disappears. 3)Text is shown at current cursor position rather than at the end of statement.

I have also raised above issues on threads https://github.com/microsoft/vscode/issues/207414 and https://github.com/microsoft/vscode/issues/207753 but did not get resolution yet

I was wondering do we need to implement any other provider or i am using the provider in wrong way(particularly related to range) or is their any bug with vscode?

Below is the code snippet. ( please note, inlineCompletionitemProvider.pos is the current position of cursor which does not change after we trigger command - editor.action.inlineSuggest.trigger

class inlineCompletionitemProvider implements vscode.InlineCompletionItemProvider { public static hint:string = ""; public static pos:vscode.Position; public static range:vscode.Range; provideInlineCompletionItems(document: vscode.TextDocument, position: vscode.Position, context: vscode.InlineCompletionContext, token: vscode.CancellationToken): vscode.ProviderResult<vscode.InlineCompletionItem[] | vscode.InlineCompletionList> { if (context.triggerKind == vscode.InlineCompletionTriggerKind.Invoke) { let vscodeRange:vscode.Range = new vscode.Range(inlineCompletionitemProvider.pos,position); let item: vscode.InlineCompletionItem = new vscode.InlineCompletionItem(${inlineCompletionitemProvider.hint},vscodeRange); return [item]; } else{ return []; } } }

//code snippet to explicit trigger inline hint provider and display them private onResult = async () => { oracleInlineCompletionitemProvider.hint = "testing accept word"; oracleInlineCompletionitemProvider.pos = activeTextEditor.selection.active; // this is cuurent cursor position. hints would be displayed at this position await vscode.commands.executeCommand('editor.action.inlineSuggest.trigger');

}

WJ-Yuan commented 7 months ago

I encountered the same problem.

In earlier versions:

In the current version:

Type: Bug

VS Code version: Code 1.88.0 (5c3e652f63e798a5ac2f31ffd0d863669328dc4c, 2024-04-03T13:26:18.741Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info |Item|Value| |---|---| |CPUs|12th Gen Intel(R) Core(TM) i7-1260P (16 x 2496)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok< br>skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|15.69GB (4.42GB free)| |Process Argv|--crash-reporter-id 8907859a-dd42-4cff-a463-eec6c8d4e7bb| |Screen Reader|no| |VM|0%|
Extensions (29) Extension|Author (truncated)|Version ---|---|--- codesnap|adp|1.3.4 tsl-problem-matcher|amo|0.6.2 regex|chr|0.4.0 vscode-eslint|dba|2.4.4 EditorConfig|Edi|0.16.4 prettier-vscode|esb|10.4.0 codespaces|Git|1.16.18 todo-tree|Gru|0.0.226 vue-snippets-self|jwy|0.0.7 i18n-ally|lok|2.12.0 gitless|maa|11.7.2 git-graph|mhu|1.30.0 vscode-docker|ms-|1.29.0 vscode-language-pack-ko|MS-|1.88.2024040309 vscode-language-pack-zh-hans|MS-|1.88.2024040309 git-emoji-message|nai|1.1.0 indent-rainbow|ode|8.3.1 svg-preview|Sim|2.8.3 vscode-rustfmt|sta|0.1.2 code-spell-checker|str|3.0.1 vscode-stylelint|sty|1.4.0 pdf|tom|1.2.2 errorlens|use|3.16.0 explorer|vit|0.4.1 vscode-icons|vsc|12.7.0 volar|Vue|1.8.27 vscode-typescript-vue-plugin|Vue|1.8.27 pretty-ts-errors|Yoa|0.5.4 type-challenges|YRM|1.15.0
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 d34g3935:30971562 fegfb526:30981948 bg6jg535:30979843 ccp2r3:30993541 dsvsc020:30976470 pythonait:31006305 gee8j676:31009558 dsvsc021:30996838 g1icg217:30999571 ```
ajaygera commented 7 months ago

This issue exists on latest vscode version 1.88. Can anyone help in resolving this issue?