Hello. I am new to Nextcloud development and VS Code. I followed the tutorial to make a Hello World app. That works fine. My question is around getting VS Code set up for developing a NextCloud app. I opened the Hello World apps folder in VS Code. It is something like /home/username/nextcloud-docker-dev/workspace/server/apps-extra/helloworld/.
I can view and edit the code in this directory but VS Code complains about not being able to find classes and types such as:
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
I have spent a good bit of time searching for how to fix this but I do not know the correct terms or something because I am not coming up with anything.
This looks like you are using Julius Knorr’s development environment. There are different options here:
Use the server as main project
You can instead open /home/username/nextcloud-docker-dev/workspace/server. Then, app classes from the current DC environment are present.
The drawback is, that the implementation is here as well and indexing that takes done time (and RAM). Nice is, that you can step-debug also parts of the core.
Use a composer package
There is a composer package that contains the interfaces only. Then, VS code should find these interface definitions in vendor. The package is called @ nextclout/ocp.
The benefit is that you just get the interfaces you are supposed to use. Nothing more.
This should be installed by default as part of the hello world app shipped from the app template.
Usage of the multi-root feature of VS code
In code, you can define a multi root project. This was another option. I used that in the past but had some problems with redundant classes found by code. That way, the UI was a bit more cluttered but okay not too bad.
One drawback I found was, that the exclusion of files (in my case fixtures of the test site and test environments inside the test site inside the app, long story) caused problems. You can try it out if it works for you.
Personal experience
I first went with the multi-root approach with my first app. However, it became apparent that it is nice to have a versatile environment where new apps can quickly be added just for evaluating a quick thing. Then the first one seemed more feasible to me personally. But this is just my taste.
Thank you! The first option worked just fine. I opened the folder and then I saved a project file. I was trying to figure out how to make in rebuild the index and then I saw the PHP plug in I was using was indexing. Now it finds the used classes.