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-13895] Code completion incrementality/AST reuse breaks with some relative paths/working dirs #60694

Open
swift-ci opened this issue Nov 24, 2020 · 2 comments

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13895
Radar rdar://problem/71712730
Original Reporter Davidee (JIRA User)
Type Bug
Environment

Tested with Xcode 12 - 12.3 beta 1

Additional Detail from JIRA
Votes 0
Component/s SourceKit-LSP
Labels Bug
Assignee None
Priority Medium

md5: 6816508ed1745e3c1d975ea58cbcece3

Issue Description:

Sourcekitd's AST reuse for code completion appears to be fragile when relative paths and/or -working-dir arguments are being used.

When this issues appears, code completion shows incrementality/AST reuse (visible by setting SOURCEKIT_LOGGING=3 and checking for the reusingastcontext flag in the sourcekit code completion reply) for ~5 seconds or so, and then loses incrementality, making something in this method the likely cause (https://github.com/apple/swift/blob/c9dbef61b2122277e42d450f34ec0f3be4fcea95/lib/IDE/CompletionInstance.cpp#L235).

Since Xcode uses absolute paths for its arguments, this is only easily reproducible in sourcekit-lsp.

Steps to reproduce:

  1. Build sourcekit-lsp from my fork which changes sourcekit-lsp's build arguments to use relative path handling; you could probably do the same for Xcode's SPM integration.

  2. Checkout and build https://github.com/apple/swift-llbuild2 using swift build

  3. Open the swift-llbuild2 checkout using an editor hooked up to your custom sourcekit-lsp (and make sure it's using the same toolchain you used to build the swift-llbuild2) and make sure you've set SOURCEKIT_LOGGING=3 to enable sourcekit logging.

  4. Navigate to https://github.com/apple/swift-llbuild2/blob/85b95bcd53b499af567d9b85cb5cdfe72b78fbbc/Sources/llbuild2/Core/Engine.swift#L55 and trigger code completion by copying and pasting "self" and then typing .

  5. Observe from the sourcekit logs that the first code completion isn't reusing the AST context. If you do a subsequent code completion within 5 seconds, it will reuse the AST context, if you wait longer than 5 seconds, the next code completion will not reuse the AST context.

@swift-ci
Copy link
Collaborator Author

Comment by David Goldman (JIRA)

Just tried reproducing this with a custom Swift toolchain for debugging as well as a development snapshot Swift toolchain but I'm running into errors building swift-llbuild2 which block me, see https://gist.github.com/DavidGoldman/933260ebc751ffe486c1537f0af4d8b6

Filed https://bugs.swift.org/browse/SR-13897 for that issue

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@ahoppen ahoppen removed the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Aug 22, 2022
@ahoppen ahoppen transferred this issue from apple/sourcekit-lsp Aug 22, 2022
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

4 participants