DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
80 stars 10 forks source link

No classes are found #45

Closed svenax closed 4 years ago

svenax commented 5 years ago

macOS: 10.14.6 phptools: 1.0.3936

In a fairly complex project using the Zend Framework 2 module structure, the Problems log fills up with thousands of "Use of unknown class" messages. Is phptools perhaps depending on the Composer autoloader to find classes? I would have expected it to build it's own dependency database.

jakubmisek commented 5 years ago

PHP Tools reads all the classes within the workspace. There might be a bug and problems are reported BEFORE we read all the files, or composer packages are not restored?

svenax commented 5 years ago

I get almost 3000 "Use of unknown class" warnings, and maybe 5 other messages in the Problems console. Nothing is logged in the Language server console. I mentioned Composer only because ZF2 does not use it, but rather its own fairly complex class loader. But that should not matter since phptools is not using it anyways.

jakubmisek commented 5 years ago

isn't it possible files containing the classes are excluded using files.exclude setting?

svenax commented 5 years ago

No, it is my own code that is not recognised.

jakubmisek commented 5 years ago

For now, I would recommend to disable workspace analysis (https://github.com/DEVSENSE/phptools-docs/issues/29)

In workspace settings or in settings.json, put following:

{
    "php.problems.workspaceAnalysis": false
}

This should speed up workspace loading, and you'll still see problems in opened documents.

svenax commented 5 years ago

PHP Tools is not usable for me until it can reliably analyse the entire workspace. I'm reverting to using PHP IntelliSense for the time being.

jakubmisek commented 5 years ago

I understand,

As mentioned, you can disable the background analysis in your settings.json (https://github.com/DEVSENSE/phptools-docs/issues/45#issuecomment-529117019) so it does nothing on background like the other extensions do

{
    "php.problems.workspaceAnalysis": false
}

Also recommending to exclude problems reporting in /vendor folder

{
    "php.problems.exclude": {
        "vendor": true
    },
}

I hope it helps.

addshore commented 4 years ago

It looks like I encountered a similar issue with tens of thousands of issues being reported.

Adding "php.problems.workspaceAnalysis": false to my settings emptied out this list but problems remained in the file that I have open.

A concrete example would be this wfDebugLog global function: image This is included in the file includes/GlobalFunctions.php in my workspace and I'm encountering the error in extensions/Wikibase/lib/includes/Store/Sql/Terms/Util/ReplicaMasterAwareRecordIdsAcquirer.php

I also had this issue with a few classes, but managed to make those issues disappear by opening the files that the classes were defined in. That doesn't appear to work for the global function.

Seemingly cuting and pasting the content of the whole file seemed to make all of these false-positive problems go away (a trick I have used with phpstorm in the past when it messes something up). Not sure if any of these rambling helps improve the situation at all :)

jakubmisek commented 4 years ago

Seems some files (or all of them) may not be scanned upon startup causing the issues above. Thank you for all the hints, we'll be working on it.

addshore commented 4 years ago

If you want any debugging help / if I can provide any logs etc just give me a poke!

jakubmisek commented 4 years ago

@addshore we have tried to replicate the issue in several ways but not succeeded.

May I ask you for more details;

image

image

Thank you!

addshore commented 4 years ago

So I am running with vscode on Windows but connecting to WSL, so all of my code is there. I'm running with MediaWiki core and also a collection of extensions.

adam@adsh+wsl:~/dev/git/gerrit/mediawiki/core/extensions (master)$ $ ls
3D                  Citoid                 ExtensionDistributor  JsonConfig                  Newsletter           README                 TorBlock                   WikibaseLexeme
AbuseFilter         CodeEditor             FeaturedFeeds         JsonData                    Nuke                 ReadingLists           Translate                  WikibaseLexemeCirrusSearch
AdvancedSearch      CodeMirror             FileExporter          Kartographer                OATHAuth             Renameuser             TranslateSvg               WikibaseManifest
AntiSpoof           Cognate                FileImporter          LabeledSectionTransclusion  OAuth                RevisionSlider         TranslationNotifications   WikibaseMediaInfo
ApiFeatureUsage     Collection             FlaggedRevs           Linter                      OAuthAuthentication  Score                  Transliterator             WikibaseMobile
ApprovedRevs        CommonsMetadata        Flow                  LocalisationUpdate          ORES                 Scribunto              TrustedXFF                 WikibaseQualityConstraints
ArticlePlaceholder  ConfirmAccount         Gadgets               LoginNotify                 OggHandler           SecureLinkFixer        TwoColConflict             Wikidata.org
Babel               ConfirmEdit            GeoData               Mailgun                     OpenID               SecurePoll             TwoFactorAuthentication    WikidataEntitySuggester
BetaFeatures        Contributors           GlobalBlocking        Maps                        OpenIDConnect        SiteMatrix             UniversalLanguageSelector  WikidataPageBanner
BoilerPlate         ContributorsAddon      GlobalCssJs           MassAction                  PageImages           SpamBlacklist          UrlShortener               WikimediaBadges
BounceHandler       DeleteBatch            GlobalPreferences     MassMessage                 PageViewInfo         SyntaxHighlight_GeSHi  UserMerge                  WikimediaEditorTasks
Campaigns           Disambiguator          GlobalUsage           MassMessageEmail            PagedTiffHandler     SyntaxHighlighter      VipsScaler                 WikimediaEvents
Capiunto            DiscussionTools        GlobalUserPage        Math                        ParserFunctions      TemplateData           VisualEditor               WikimediaMessages
CategoryTree        DismissableSiteNotice  Graph                 MathSearch                  ParserHooks          TemplateInfo           WSOAuth                    WikimediaPageViewInfo
CentralAuth         Echo                   GraphViz              MediaModeration             PdfHandler           TemplateSandbox        WebAuthn                   WikimediaShopLink
CentralNotice       Elastica               GuidedTour            MobileApp                   PluggableAuth        TemplateStyles         WikiEditor                 Wikisource
CharInsert          ElectronPdfService     ImageLink             MobileFrontend              PluggableSSO         TemplateWizard         WikiLexicalData            XAnalytics
CheckUser           EntitySchema           ImageMap              MoveToCommons               Poem                 TextExtracts           WikiLove                   cldr
CirrusSearch        EventBus               Interwiki             MoveToCommonsClient         PoolCounter          Thanks                 Wikibase                   examples
Cite                EventLogging           InterwikiMap          MultimediaViewer            ProofreadPage        TimedMediaHandler      WikibaseCirrusSearch       timeline
CiteThisPage        EventStreamConfig      InterwikiSorting      NavigationTiming            PropertySuggester    TitleBlacklist         WikibaseImport             wikihiero

I ran vscode by running code . in WSL, which I imagine is the equivalent of just opening the project directory.

what is the path to your project? is it on the local disk drive?

In the WSL context, the path is local and at ~/dev/git/gerrit/mediawiki/core.

I just turned workspaceAnalysis back on for a second to have a look around and see how it is performing now.

image

The OUTPUT panel for the language server shows the following:

PHP Tools server started.
    Path: /home/adam/.vscode-server/extensions/devsense.phptools-vscode-1.0.4698/out/server/Devsense.PHP.LanguageServer.dll
    PID: 5151
    Processing files: .php; .php5

No errors, but also no output, should there be any? Is it possible that for such a large project it just needs lots more time to process?

I have nothing in my files.exclude (other than the defaults) image

I'll leave it running for a bit and see if anything changes, but I don't see any processes seeming to do much.

adam@adsh+wsl:~/dev/git/gerrit/mediawiki/core/extensions (master)$ $ ps 5151
  PID TTY      STAT   TIME COMMAND
 5151 pts/1    Sl+    1:12 /home/adam/.vscode-server/extensions/devsense.phptools-vscode-1.0.4698/out/server/Devsense.PHP.LanguageServer
jakubmisek commented 4 years ago

@addshore nice, thank you very much, we'll be processing it for a while.

The first possible issue on our side might be the lack of support for UNC paths and remote paths, but since you have 31K+ problems found, it'll be probably something else..

addshore commented 4 years ago

Is there any way I can turn on more verbose output and perhaps get you all some more hints? Or have you managed to reproduce the issue as I described? :)

addshore commented 4 years ago

Another few days on and I now only have 5k reported errors with workspace analysis turned on

image

And every time I open one of these files that vscode thinks is missing it will then realize that it is there and those problems go away!

Is there a way to make phptools reload every file in a workspace?

jakubmisek commented 4 years ago

@addshore thanks for the update. The last version improved the analysis, so a lot of falsely reported problems went away.

PhpTools suppose to load and analyze all the files in the workspace, so it is an obvious bug and we're trying to fix it :/ we have a few hints, I hope the next update makes it another step better

addshore commented 4 years ago

So I spotted that I got another update today:

Downloading PHP Tools dependencies (linux-x64-1.0.4934) ...

And now it is only reporting 3k errors for me with workspace analysis on:

image

Seems like yours making some great progress

jakubmisek commented 4 years ago

Yes, thank you for noticing and for the feedback.

1.0.4934 (July 19, 2020) updates analysis so it does not report some of the false problems. It also improves editing and initial workspace loading, but we're still working on it.

Please if you have a piece of code with a wrong problem reported, we'd be happy for an issue.

addshore commented 4 years ago

As I have been browsing around it has gone back up to 7k+ problems.

Most of these seem to be "Use of unknown class", for example: image Also "Call to unknown function" image and also unknown constants

jakubmisek commented 4 years ago

@addshore I guess those classes/functions actually exist in the workspace :)

If you search for them using Ctrl+P, does the editor find them?

addshore commented 4 years ago

@addshore I guess those classes/functions actually exist in the workspace :)

Yes

If you search for them using Ctrl+P, does the editor find them?

No :/ "No Matching Workspace Symbols"

And as mentioned before, the moment I open each of these files that contains the class the problems go away. But needing to do that for the hundreds or thousands of files is not an ideal solution :/

jakubmisek commented 4 years ago

May I ask what you have in Settings / files.exclude: image


@addshore we have released an update which logs most of the unexpected failures during workspace load. You can find it in Output panel, "PHP Language Server" group: image

addshore commented 4 years ago
PHP Tools server started.
    Path: /home/adam/.vscode-server/extensions/devsense.phptools-vscode-1.0.4962/out/server/Devsense.PHP.LanguageServer.dll
    PID: 14268
    Processing files: .php; .php5

Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/Elastica/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/CodeEditor/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/GuidedTour/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/DeleteBatch/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/DiscussionTools/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/NavigationTiming/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/CentralAuth/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/Graph/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/WikimediaPageViewInfo/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/WikibaseLexemeCirrusSearch/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/TextExtracts/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/Citoid/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/WikimediaShopLink/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/CentralNotice/.git' is excluded.
Directory '/home/adam/dev/git/gerrit/mediawiki/core/extensions/UniversalLanguageSelector/.git' is excluded.
Too many open files at EnumeratePhpFilesInFolder
Too many open files at EnumeratePhpFilesInFolder
Too many open files at EnumeratePhpFilesInFolder
Too many open files at EnumeratePhpFilesInFolder

That last message continues quite a lot...

My files.exclude is default afaik

image

jakubmisek commented 4 years ago

excellent! thank you, Too many open files seems to be the clue!

edit: The quick workaround is to increase macOS's configuration ulimit which is really low by default. We'll improve this in the next update.

jakubmisek commented 4 years ago

Just released an update that should fix the issue. Any feedback would be appreciated :)

jakubmisek commented 4 years ago

Does the workspace load normally now? We are currently working on "problems analysis", trying to not report redundant or falsely detected problems in general.

addshore commented 4 years ago

I havn't seem any classes etc that I know to exist report as missing in the last days, so I think this bit is now correct for me.

jakubmisek commented 4 years ago

@addshore awesome, so now we have tons of "problems" reported and we have to deal with them. I'm closing this issue, and please let's open a new one where we can discuss specific code fragments reported as a warning?