Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generated by build plugin is ignored #665

Open
adam-fowler opened this issue Nov 11, 2022 · 11 comments
Open

Source generated by build plugin is ignored #665

adam-fowler opened this issue Nov 11, 2022 · 11 comments

Comments

@adam-fowler
Copy link
Contributor

adam-fowler commented Nov 11, 2022

The source code generated by a SwiftPM build plugin does not get parsed by SourceKit-LSP. So any code referencing generated code is considered an error and "Go to definition..." etc don't work

I have a sample project here https://github.com/adam-fowler/soto-codegenerator-plugin-test. It has an AWS model file that defines the API for the SNS service from AWS. The build plugin generates source code from this and the generated code is used in the file SNSTest.swift. SourceKit-LSP reports 4 problems in this file even though the project builds fine

@ahoppen
Copy link
Member

ahoppen commented Nov 11, 2022

rdar://102242345

@adam-fowler
Copy link
Contributor Author

It looks like this is not completely true. I can get code completion etc to work by restarting the sourcekit-lsp server. I'm guessing this is a similar issue to #620

@mpilman
Copy link

mpilman commented Apr 8, 2023

I am running into the same problem. In my project I am using protobuf, grpc, and a custom code generator and LSP isn't able to find any of the generated code (not even after restarting VSCode, LSP, reloading the window, clean and rebuild...)

I created a tiny [reproduction project(https://github.com/mpilman/ProtoRepro) (on macOS the protoc has to be installed and the environment variable PROTOC_PATH=/opt/homebrew/bin/protoc has to be set in order for this to build).

This is what the swift-file looks like in VSCode after the project has been successfully built:

image

@smumriak
Copy link

smumriak commented Jul 2, 2023

I've moved my generated code from manually running the tool to being a plugin yesterday and I'm affected by this too. The repo is located here, tho it's not a tiny example :)

@adam-fowler
Copy link
Contributor Author

adam-fowler commented Jul 7, 2023

This appears to be resolved in the latest swift 5.9 toolchain. But we still have the issue where we cannot use go to definition within generated code.

EDIT: This still needs a LSP restart

@ahoppen
Copy link
Member

ahoppen commented Jul 12, 2023

The problem for not getting any semantic functionality in the generated files is that we don’t get compiler arguments for them. As I understand, being able to get them requires a couple of non-trivial changes to SwiftPM, which we’re now tracking in swiftlang/swift-package-manager#6700.

@dabrahams
Copy link

dabrahams commented Dec 21, 2023

FWIW: Restarting SourceKit doesn't help me at all; I need to manually copy the generated source file into my project folder to get things to work.

@dangdennis
Copy link

I've encountered this issue since I've started a swift vapor project with vscode. But suddenly the lsp is able to parse the generated files after I switched to xcode today to develop the module that uses the swift openapi plugin and exports the generated source code.

A little unwilling to try to replicate by deleting my .build since it's actually working for once 😅 .

@ahoppen
Copy link
Member

ahoppen commented May 3, 2024

FWIW, a workaround for now is to generate all files into their own module with public access level (and leave the module otherwise empty) and then import that module with the generated code.

@adam-rocska
Copy link

adam-rocska commented May 7, 2024

@ahoppen ’s tip seems to work for me too. Quite hacky though 😅

EDIT: In my case, I made it package scoped.

@bnbarham
Copy link
Contributor

This should be fixed by the following:
swiftlang/swift-package-manager#8286
#1973

Note that it is not enabled when background indexing is disabled - we'd need swiftlang/swift-package-manager#6700 to fix that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants