salesforcedx-vscode icon indicating copy to clipboard operation
salesforcedx-vscode copied to clipboard

Autocomplete / IntelliSense not working

Open lukethacoder opened this issue 4 years ago • 18 comments

Summary

Autocomplete / IntelliSense not working for Apex code. On both SObjects and built in Apex functions.

Steps To Reproduce:

  1. Open Salesforce project, with existing classes.
  2. Run sfdx sobject definitions refresh -u ORG_NAME
  3. Type something and wait for the autocomplete

Expected result

Should show autocomplete/IntelliSense or snippet suggestion

Actual result

No autocomplete suggestions.

Additional information

SObject definitions pull in nicely.

Screenshot_2

Autocomplete doesnt work so nicely.

Screenshot_1

Additional information VS Code Version: 1.44.2 SFDX CLI Version: 7.56.1-2773b53bf5 OS and version: Windows 10 Home, Version 1909 JAVA Version: jdk-11.0.7

Have tried using various environments, both sandboxes and scratch orgs. Projects have very few apex classes, or any other components.

Test Classes do work very nicely, and I have double checked my JAVA_HOME/JDK_HOME paths (in addition to adding "salesforcedx-vscode-apex.java.home": "C:\\Program Files\\Java\\jdk-11.0.7", to preferences.

Apex Language Server output log

19:59:22.493 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Scanning built-in and system Apex types.
May 03, 2020 7:59:23 PM apex.jorje.parser.impl.BaseApexLexer dedupe
INFO: Deduped array ApexLexer.DFA22_transition. Found 7075527 shorts which is 13MB not including array overhead. Removed 6418975 shorts which is 12MB not counting array overhead. Took 12 ms.
19:59:26.822 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Patching standard library for System.Database.* methods
19:59:26.832 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Done patching standard library for System.Database.* methods
19:59:28.150 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: Scanning user-defined types.
19:59:28.154 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Scanning built-in and system Apex types took 5659 ms.
19:59:38.908 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: Scanning user-defined types took 10740 ms.

Other related issues https://github.com/forcedotcom/salesforcedx-vscode/issues/2095 https://github.com/forcedotcom/salesforcedx-vscode/issues/920 https://github.com/forcedotcom/salesforcedx-vscode/issues/935

lukethacoder avatar May 03 '20 10:05 lukethacoder

Is there a work-around for this issue? Barring that, is there a specific version set (VSCode, SFDX) that I can install to get fully-functional autocomplete for Apex classes? For what it's worth, I'm seeing the same logging output for the Apex Language Server.

jerhewet avatar May 26 '20 15:05 jerhewet

autocomplete is not working on trigger files it works on certain variables but not work on other ones

image

image (it shows no suggestions)

(no errors on apex language server) vscode: 1.51.1 java: 11.0.9

gab95 avatar Dec 09 '20 20:12 gab95

@gab95 I have the same issue on autocomplete not working for variables defined inside trigger files. No issue on class files.

kkevinreyes avatar Dec 30 '20 03:12 kkevinreyes

Thanks for the additional info @kkevinreyes

smaddox-sf avatar Jan 16 '21 00:01 smaddox-sf

@kkevinreyes @gab95 We are looking for an open source repository where we can reproduce this issue for testing. Do either of you happen to have an example project where completions from within the trigger files are not working?

Please also include:

  • VS Code Extension version
  • OS and version
  • Enable the setting "salesforcedx-vscode-apex.advanced.enable-completion-statistics": "true". This will output additional information into the Apex Language Server output channel. It will help us determine if this is a performance issue.

Thank you again for your help!

sfsholden avatar Apr 02 '21 18:04 sfsholden

This issue has been automatically closed because there has been no response to our request for more information from the original author. Currently, there is not enough information provided for us to take action. Please reply and reopen this issue if you need additional assistance.

no-response[bot] avatar Apr 09 '21 19:04 no-response[bot]

Still no luck with autocomplete in either class files or triggers.

image

enabled "salesforcedx-vscode-apex.advanced.enable-completion-statistics": "true" and got an extra 2 lines of logging (last 2 lines here).

09:52:47.454 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Scanning built-in and system Apex types.
Apr. 10, 2021 9:52:48 AM apex.jorje.parser.impl.BaseApexLexer dedupe
INFO: Deduped array ApexLexer.DFA22_transition. Found 7075528 shorts which is 13MB not including array overhead. Removed 6418975 shorts which is 12MB not counting array overhead. Took 10 ms.
09:52:50.104 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Patching standard library for System.Database.* methods
09:52:50.109 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Done patching standard library for System.Database.* methods
09:52:50.743 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: Scanning user-defined types.
09:52:50.744 [Apex Prelude Service STARTING] INFO  a.j.l.i.s.ApexPreludeManagedService - Scanning built-in and system Apex types took 3290 ms.
09:53:03.619 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: StandardObjects: 731
09:53:03.619 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: CustomObjects: 6
09:53:03.619 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: ApexFiles: 157
09:53:03.619 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: ErrorFiles: 65
09:53:03.619 [ApexIndexer STARTING] INFO  a.jorje.lsp.impl.index.ApexIndexer - ApexIndexer: Scanning user-defined types took 12860 ms.
Apr. 10, 2021 9:57:50 AM org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint notify
INFO: Unsupported notification method: $/setTraceNotification

VS Code Version: 1.55.1 Salesforce Extension Pack (VS Code): 51.8.0 SFDX CLI Version: 7.90.2 OS: Windows 10 Home, Version 10.0.19043 Java version: jdk-11.0.7

lukethacoder avatar Apr 10 '21 00:04 lukethacoder

This issue has been linked to a new work item: W-9145638

uip-robot-zz avatar Apr 15 '21 23:04 uip-robot-zz

@lukethacoder Have you tried opening a sample-app project like dreamhouse-lwc? I'd like to see if even just a basic demo works. If still no luck there, might try a more nuclear option of uninstalling the extension pack, closing vs code, reopen vs code, and reinstall the extension pack. Try to open dreamhouse-lwc again and see if that works.

If we can get it to work with dreamhouse, that at least tells us there's something about the project structure or Apex contents of the projects you're working with that the language server isn't handling properly. If we can't, that seems like a sign that maybe something with the machine's setup is causing a communication problem.

Do other language server features work? If you right click a method or Apex class reference and select "find all references" or "rename symbols", does it do so successfully? This also will help isolate the problem.

brpowell avatar Apr 30 '21 20:04 brpowell

I reckon it might be something machine related. Have nuked vs code + the sf extension pack multiple times over the past few months, again today, and even setup on a new machine with similar issues.

Installed and setup the dreamhouse-lwc project to see if that would work, but it still isn't playing nice.

image

Right clicking on an apex method doesn't even give the option for "find all references" or "rename symbols".

image

Apex Language Server logs look the same as posted up further.

Was thinking maybe my Java install might have been the issue (still might be) but I still have intelliJ and Illuminated Cloud 2 working just fine. This issue is one of the only reason I havn't fully moved over to VS Code.

VS Code Version: 1.55.2 Salesforce Extension Pack (VS Code): 51.11.0 SFDX CLI Version: 7.99.0 OS: Windows 10 Home, Version 10.0.19043 Java version: jdk-11.0.7

lukethacoder avatar May 01 '21 06:05 lukethacoder

@lukethacoder did you ever get to the bottom of your issue? I'm seeing exactly the same behaviour.

My personal Windows PC

  • Autocomplete works for Apex class files
  • Autocomplete does not work for Apex trigger files

My work mac

  • Autocomplete works for both

I'm in the process of completely removing AdoptOpenJK and reinstalling from fresh to see if that makes any difference.

I'll also try cloning the dreamhouse-lwc and see if it's potentially a machine or project based issue.

benji1304 avatar Mar 22 '22 19:03 benji1304

I've wiped and reinstalled AdoptOpenJDK,

New triggers are autocompleting, but existing triggers in my project are not.

benji1304 avatar Mar 22 '22 21:03 benji1304

Was about to comment that new triggers are working for me as well! That is really strange that old ones are not.

randi274 avatar Mar 22 '22 21:03 randi274

Yup, exactly what i'm seeing. Nothing obvious in the Apex Language Server log either

This is my existing trigger

10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Completions for file:///c:/Users/ben/apexacademy/force-app/main/default/triggers/WarrantySummary.trigger took 6 ms.
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: LocalVariableNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: FieldNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: MethodNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: MembersCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TypesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: SystemNamespaceCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TriggerKeywordCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 1
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TriggerContextVariablesCompletionStrategy; Time Taken [ms]: 2; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: EmbeddedSoqlCompletionStrategy; Time Taken [ms]: 1; Number of Items Added: 0
10:40:27.160 [ForkJoinPool.commonPool-worker-23] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: SObjectFieldNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0

This is my new trigger

10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Completions for file:///c:/Users/ben/apexacademy/force-app/main/default/triggers/testTrigger.trigger took 3 ms.
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: LocalVariableNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: FieldNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 1
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: MethodNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: MembersCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TypesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 35
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: SystemNamespaceCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 2
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TriggerKeywordCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 1
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: TriggerContextVariablesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: EmbeddedSoqlCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0
10:42:48.140 [ForkJoinPool.commonPool-worker-9] INFO  a.j.l.i.c.ApexCompletionStrategyAggregator - Strategy: SObjectFieldNamesCompletionStrategy; Time Taken [ms]: 0; Number of Items Added: 0

benji1304 avatar Mar 22 '22 21:03 benji1304

Is the content of the triggers identical? Are they both using the same API version?

randi274 avatar Mar 22 '22 21:03 randi274

Does the ‘refresh object definitions’ sfdx command somehow solve your issue? Its been deemed to solve some autocomplete issues in the past, but I have no idea if it will help in your case with the trigger/apex. Thought I’d ask because i dont see mention of that factor here.

-- Sent from Gmail Mobile

peternoges avatar Mar 22 '22 21:03 peternoges

Is the content of the triggers identical?

Nope. I'll try this.

Are they both using the same API version?

Both in the same project - so yes?

benji1304 avatar Mar 22 '22 21:03 benji1304

Did some testing from the suggestion from @randi274

It looks like a scoping problem (forgive me if i use the wrong terminology, i'm still learning some of this! 😄 )

trigger testTrigger on Case (before insert) {

    Boolean thisIsFalse; 

    for( Case c : Trigger.new) {
        Boolean thisIsTrue;

        }
}

image

If I try to complete this then I get thisIsFalse, but not thisIsTrue

benji1304 avatar Mar 22 '22 22:03 benji1304