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

[SR-3121] Auto-completion and Syntax coloring don't work most of the time with SwiftPM generated Xcode projects #5182

Closed
swift-ci opened this issue Nov 3, 2016 · 20 comments
Assignees
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Nov 3, 2016

Previous ID SR-3121
Radar rdar://problem/29825757
Original Reporter paulofaria (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 1
Component/s Package Manager
Labels Bug
Assignee @aciidb0mb3r
Priority Medium

md5: 8ac4d586758a2b680111b946a047c3be

is duplicated by:

  • SR-3200 Cannot debug SwiftPM package in Xcode

relates to:

  • SR-3086 Xcode project generation puts modules from external packages together with local ones

Issue Description:

Auto-completion and Syntax coloring don't work most of the time with Xcode projects generated by SwiftPM 3.0.1

Steps to reproduce:

clone a large SwiftPM package like https://github.com/Zewo/Zewo
generate Xcode project

swift package generate-xcodeproj

notice lack of auto-completion and syntax coloring

@ddunbar
Copy link
Member

ddunbar commented Nov 3, 2016

Users are reporting that this regressed between using the 3.0.1 and the 3.0 versions of the package manager project generation. I'm not really sure how this is possible, but it has been reported by multiple people...

@ddunbar
Copy link
Member

ddunbar commented Nov 3, 2016

/cc @aciidb0mb3r @abertelrud

@ankitspd
Copy link
Member

ankitspd commented Nov 3, 2016

Xcode version ?

@abertelrud
Copy link
Contributor

More information would be useful. I consistently get code completion in the generated project for SwiftPM itself. I know that there have been some changes re: settings SDKROOT etc... it's possible that that has an effect. I'll try with Zewo specifically, though.

@abertelrud
Copy link
Contributor

I can reproduce this for Swift sources (C sources work fine), but oddly, most indexer features work just fine: I can jump-to-definition, I can see all callers in the structure navigator, etc.

So the question is what's different in the code completion context between, Zewo and, say, SwiftPM itself.

And I have verified that this problem is in the source files that are in the top-level package itself; it's not a case of external dependencies vs internal source files.

@swift-ci
Copy link
Contributor Author

Comment by Paulo Ricardo Lopes de Faria (JIRA)

Just so you know. This problem also happens with repos that have no dependency at all like:

https://github.com/GraphQLSwift/GraphQL

@ddunbar
Copy link
Member

ddunbar commented Nov 11, 2016

Could this be related to toolchains or the SWIFT_VERSION setting?

@abertelrud
Copy link
Contributor

Possibly — when I was able to reproduce this, with Zewo, the problem at the fundamental Xcode level was that the indexing methods reported no compiler settings at all; I haven't been able to get back yet to investigating why not, but since Zewo does interesting things with symlinked source files, I thought that was part of the problem. I'll check GraphQL as well, and if it more traditional in its source layout, that could rule out some of the variables and help narrow this down.

@abertelrud
Copy link
Contributor

For GraphQL I am not able to reproduce this — I get code completion (once indexing as finished).
paulofariarl (JIRA User): In what version of Xcode are you seeing this? Also, are you using a custom toolchain?

@swift-ci
Copy link
Contributor Author

Comment by Paulo Ricardo Lopes de Faria (JIRA)

I was using Xcode 8.1 with Xcode's own toolchain. The code completion is lost after some time when you edit the code. In GraphQL's example I was pasting javascript code and then porting it to Swift. As soon as I pasted js code, code completion disappeared and never came back, even after I correctly translated the code, making it compile and all. The only way to bring it back was to regenerate the project. Not even closing Xcode, cleaning derived folder, etc.. would work.

@abertelrud
Copy link
Contributor

Thanks for the information, paulofaria (JIRA User). That sounds like yet another, slightly different case: if everything initially works fine but eventually stops working, then that doesn't sound the same as a project generator bug (since the project generator can't affect the project after it's been generated). It could be a SourceKit crash, or possibly a change to the project that breaks it (and that regenerating the project then "fixes" again). Are you able to reproduce this, and / or do you have a copy of the the old (broken) project I could look at?

@abertelrud
Copy link
Contributor

There's also a discussion here: Kitura/Kitura#822

@swift-ci
Copy link
Contributor Author

Comment by Paulo Ricardo Lopes de Faria (JIRA)

The problem is that Xcode projects generated with Swift 3.0 work fine. only the ones generated with Swift 3.0.1 don't. I'll try to reproduce again when I have some time. But it didn't take much. Just generate a project with SwiftPM 3.0.1, paste some rubbish and even if you delete it or fix it, auto-completion is lost forever. some of syntax coloring comes back, but not completely.

@abertelrud
Copy link
Contributor

I see. And just to clarify, for you when you generate the project with Swift 3.0, pasting the rubbish and then deleting it restores full functionality?

For me, unfortunately, I wasn't able to get the Swift 3.0-generated projects to work fine — if they did it would be great, since that would provide something to compare and contrast. In particular I used Xcode 8.0's Swift (3.0) to generate the project and was not able to get code completion to work in the Kitura-Sample project (from the thread I referenced above). I will try again also with GraphQL again (which did work for me, both in 8.0 and 8.1, but I hadn't tried the part about pasting rubbish and seeing if the code completion went away).

@swift-ci
Copy link
Contributor Author

Comment by Paulo Ricardo Lopes de Faria (JIRA)

Looks like they found a solution for Kitura-Sample project. Which is to add back a modulemap. This is still count as a bug because SwiftPM should create the modulemap if we don't provide one, right?

@ankitspd
Copy link
Member

I investigated this, there is definitely something going on with modulemaps and sourcekit.
Any latest toolchain should be good enough to reproduce this, I used swift-DEVELOPMENT-SNAPSHOT-2016-11-15-a.xctoolchain
I create a simple minimal package which contains two modules, C and Swift. The Swift module depends on the C module. C module has one function five() which returns the integer 5. The Swift module just calls and print it. The C module has a modulemap located at "Sources/see/include/module.modulemap", the indexing/autocomplete/highlighting behaviour changed based on content of the modulemap.
First unzip see.zip and run this to generate the Xcode project:
$ swift package generate-xcodeproj

1. Working case:
edit modulemap, add this line: `header "/absolute/path/to/Sources/see/include/foo.h"`
close Xcode, rm -rf derrivedData, open Xcode
Everything works.

2. Failure 1:
Remove the previous header line and add: `header "foo.h"`
close Xcode, rm -rf derrivedData, open Xcode
Project builds fine but error after indexing:
could not build Objective-C module 'see'
-> No autocomplete for five

3. Failure 2:
Remove the previous header line and add: `umbrella "."`
close Xcode, rm -rf derrivedData, open Xcode
Project builds file but error after indexing:
use of unresolved identifier 'five'
-> clicking "import see" opens a blank page

4. Failure 3:
Remove previous umbrella line and add: `umbrella "/absolute/path/to/see/Sources/see/include"`
close Xcode, rm -rf derrivedData, open Xcode
could not build Objective-C module 'see'

@ankitspd
Copy link
Member

@ddunbar @abertelrud can you forward this to someone working on sourcekit

@swift-ci
Copy link
Contributor Author

Comment by Andrey Volodin (JIRA)

I confirm this. None of my SwiftPM projects has autocompletion.

@rballard
Copy link
Contributor

This should go to Argyrios.

@ankitspd
Copy link
Member

Fixed by #907

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants