VS Code - Completion is terrible, is it my setup?

Viewed 1587

Code completion and intellisense in VS Code is absolutely god-awful for me. In every language. I have extensions installed and updated but its always absolute trash.

import pandas as pd
data_all = pd.read_csv(DATA_FILE, header=None)
data_all. (press tab)

No suggestions.

Do you really not know its a Pandas DataFrame object, its literally the line above?

I have this issue in python, in ruby/rails, pretty much every langauge i try to use the completion is absolute garbage. Do i have an extension that is breaking other extensions? is code jsut this bad? Why is it so inexplicably useless?

Installed Currently:

abusaidm.html-s

nippets@0.2.1  
alefragnani.numbered-bookmarks@8.0.2  
bmewburn.vscode-intelephense-client@1.6.3  
bung87.rails@0.16.11  
bung87.vscode-gemfile@0.4.0  
castwide.solargraph@0.21.1  
CoenraadS.bracket-pair-colorizer@1.0.61  
donjayamanne.python-extension-pack@1.6.0  
ecmel.vscode-html-css@1.10.2  
felixfbecker.php-debug@1.14.9  
felixfbecker.php-intellisense@2.3.14  
felixfbecker.php-pack@1.0.2  
formulahendry.auto-close-tag@0.5.10  
golang.go@0.23.2  
groksrc.ruby@0.1.0  
k--kato.intellij-idea-keybindings@1.4.0  
KevinRose.vsc-python-indent@1.12.0  
Leopotam.csharpfixformat@0.0.84  
magicstack.MagicPython@1.1.0  
miguel-savignano.ruby-symbols@0.1.8  
ms-dotnettools.csharp@1.23.9  
ms-mssql.mssql@1.10.1  
ms-python.python@2021.2.636928669  
ms-python.vscode-pylance@2021.3.1  
ms-toolsai.jupyter@2021.3.619093157  
ms-vscode.cpptools@1.2.2  
rebornix.ruby@0.28.1  
sianglim.slim@0.1.2  
VisualStudioExptTeam.vscodeintellicode@1.2.11  
wingrunr21.vscode-ruby@0.28.0  
Zignd.html-css-class-completion

@1.20.0

1 Answers

If you check the IntelliSense of the read_csv() method (By hovering your mouse over it), you will see that it returns a DataFrame object

(function)
read_csv(reader: IO, sep: str = ...,

#Okay... very long definition but scroll to the end... 

 float_precision: str | None = ...) -> DataFrame

But if you use IntelliSense check the variable data_all

import pandas as pd
data_all = pd.read_csv(DATA_FILE, header=None)

It is listed as the default data type in python: Any. That's why your compiler isn't generating the autocomplete.

So, you simply need to explicitly tell your compiler that it is, in fact, a DataFrame object as shown.

import pandas as pd
from pandas.core.frame import DataFrame
DATA_FILE = "myfile"
data_all:DataFrame = pd.read_csv(DATA_FILE, header=None)
# Now all autocomplete options on data_all are available!

It might seem strange why the compiler cannot guess the data type in this example until you realize that the read_csv() method is overloaded with many definitions, and some of them return objects as Any type. So the compiler assumes the worst-case scenario and treats it as an Any type object unless specified otherwise.

Related