Commit Graph

414 Commits

Author SHA1 Message Date
Alex Hoppen
e5c521c999 [CursorInfo] Fix issues found by the stress tester 2023-03-20 08:09:10 -07:00
Alex Hoppen
eb6729754d [IDE] Report ambiguous cursor info results 2023-03-20 08:09:10 -07:00
Ben Barham
eec2848508 [SourceKit] Stop using isSystemModule to represent "non-user" modules
Rather than using `ModuleDecl::isSystemModule()` to determine whether a
module is not a user module, instead check whether the module was
defined adjacent to the compiler or if it's part of the SDK.

If no SDK path was given, then `isSystemModule` is still used as a
fallback.

Resolves rdar://89253201.
2023-03-15 14:29:48 -07:00
Nuri Amari
86c5698780 Implement importing of forward declared objc protocols and interfaces
This modifies the ClangImporter to introduce an opaque placeholder
representation for forward declared Objective-C interfaces and
protocols when imported into Swift.

In the compiler, the new functionality is hidden behind a frontend
flag -enable-import-objc-forward-declarations, and is on by default
for language mode >6.

The feature is disabled entirely in LLDB expression evaluation / Swift
REPL, regardless of language version.
2023-03-07 16:00:16 -08:00
Alex Hoppen
47607f630c [IDE] Don't set LeaveClosureBodiesUnchecked for solver-based cursor info 2023-02-28 17:28:01 +01:00
Ben Barham
d206e1baa1 [Test] Re-enable and cleanup some cursor info tests
Re-enable `static_vs_class_spelling.swift` - it was just missing the
`-target` in the `sourcekitd-test` lines.

While here, cleanup all the cursor info tests that used `split_file` to
use `split-file` instead.

Resolves rdar://105287822.
2023-02-10 19:33:15 -08:00
Ben Barham
ff8f632f2b [Test] Temporarily disable failing test to unblock CI 2023-02-10 11:39:19 -08:00
Alex Hoppen
a9cba5457c [CursorInfo] Fix a bug that caused solver-based cursor info to crash if invoked on a symbol from a different module 2023-02-09 23:29:07 +01:00
Alex Hoppen
3e460630b7 [CursorInfo] Fix bug when performing solver-based cursor info on Self 2023-02-09 23:29:07 +01:00
Alex Hoppen
e7ee839189 [CursorInfo] A few miscellaneous fixes to the AST-based cursor info and new test cases
In these cases the solver-based and AST-based cursor info differed in their results. Fix the AST-based cursor info to return the correct results and add test cases to make sure the solver-based implementation doesn’t regress them.
2023-02-09 23:29:07 +01:00
Alex Hoppen
fcc5d98f1c [CursorInfo] Deliver results from solver-based cursor info
Running the SourceKit stress tester with verification of solver-based cursor info returned quite a few differences but in all of them, the old AST-based implementation was actually incorrect. So, instead of verifying  the results, deliver the results from solver-baesd cursor info and only fall back to AST-based cursor info if the solver-based implementation returned no results.

rdar://103369449
2023-02-07 14:53:54 +01:00
Alex Hoppen
9dfeb0a560 [CursorInfo] Fix a bug that caused incorrect discriminators to be assigned to values in completion-like cursor info 2023-02-04 08:51:41 +01:00
Alex Hoppen
a5f85ee10c [SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
The main problem that prevented us from reusing the ASTContext was that we weren’t remapping the `LocToResolve` in the temporary buffer that only contains the re-parsed function back to the original buffer. Thus `NodeFinder` couldn’t find the node that we want to get cursor info for.

Getting AST reuse to work for top-level items is harder because it currently heavily relies on the `HasCodeCompletion` state being set on the parser result. I’ll try that in a follow-up PR.

rdar://103251263
2023-02-02 22:03:25 +01:00
Alex Hoppen
1ed94ff994 [SourceKit] Trigger generation of synthesized accessors in solver-based cursor info 2023-02-02 22:03:25 +01:00
Alex Hoppen
846a39d86b [IDE] Type check property wrappers so their USRs can be reported in cursor info 2023-02-02 22:03:25 +01:00
Alex Hoppen
ec1ca7f8eb [Sema] Pass self nominal type as a parameter to CheckRedeclarationRequest
The self nominal type decl needs to be passed as a parameter in here so this request doesn't tigger self nominal type computation, which results in an assertion failure.
2023-02-02 22:03:25 +01:00
Alex Hoppen
e47aea448e [SourceKit] Disable completion-like cursor info for ParamDecls 2023-02-02 22:03:25 +01:00
Alex Hoppen
ab8b4a2b5d Merge pull request #62637 from ahoppen/ahoppen/stmtcondition-at-loc
[Sema] Teach typeCheckASTNodeAtLoc to check StmtConditionElement
2023-01-31 21:12:27 +01:00
Alex Hoppen
5469760b20 Merge pull request #62636 from ahoppen/ahoppen/always-sourcedocinfo
[SourceKit] Retrieve swiftsourcedocinfo for code completion request
2023-01-31 21:11:44 +01:00
Doug Gregor
db801afbe9 Handle null macro references in the semantic annotator 2023-01-04 10:56:57 -08:00
Doug Gregor
9e61b01ec1 Rework computation of local discriminators for named entities.
Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.

Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.

There are a few interesting cases in here:
* There was a potential mangling collision with local property
wrappers because their generated variables weren't getting local
discriminators
* $interpolation variables introduced for string interpolation weren't
getting local discriminators, they were just wrong.
* "Local rename" when dealing with captures like `[x]` was dependent on
the new delcaration of `x` *not* getting a local discriminator. There
are funny cases involving nesting where it would do the wrong thing.
2022-12-21 15:01:07 -08:00
Alex Hoppen
07eb645159 [Sema] Teach typeCheckASTNodeAtLoc to check StmtConditionElement
Type checking a StmtConditionElement is slightly different than type checking the VarDecl declared by it because it doesn’t complain about redeclaration like `if let myVar = myVar`. Thus, we need to handle it in `typeCheckASTNodeAtLoc`
2022-12-16 11:24:36 +01:00
Alex Hoppen
c47a322b9a [SourceKit] Retrieve swiftsourcedocinfo for code completion request
We need swiftsourcedocinfo for cursor info and to be able to reuse the ASTContext from code completion for cursor info, we need to also retrieve the sourcedocinfo for code completion requests.
2022-12-16 11:22:43 +01:00
Alex Hoppen
39f8fa5c1c [SourceKit] Pass target-triple in new SourceKit test
Fixes rdar://103268363
2022-12-13 12:56:25 +01:00
Ben Barham
acc462108b [Test] Temporarily disable failing test to unblock CI (#62536)
Tracking re-enabling in rdar://103268363.
2022-12-12 13:57:03 -08:00
Alex Hoppen
9a0a7722f9 [IDE] Disable a few code completion specific paths for solver-based CursorInfo
The lexer will be responsible for knowing whether we have a code completion token, everything else will also work for other IDE inspection features.

The changes start to really make sense once I rename CodeCompletion -> IDEInspection in a lot of places.
2022-12-10 12:12:21 +01:00
Alex Hoppen
e777d37e20 [SourceKit] Don't ignore swiftsourceinfo for solver-based cursor info
Cursor infor needs source info for referenced decls.
2022-12-08 14:39:15 +01:00
Alex Hoppen
1395928d45 [IDE] Decrement the global closure discriminator by one before performing the second code completion pass
Otherwise, the closure discriminator will be incremented by one when the closure witht he code completion token is parsed a second time during the second pass, and thus it would receive a different discriminator during the second pass.
2022-12-08 14:39:15 +01:00
Alex Hoppen
0dfcf59a33 [IDE] Run RecontextualizeClosures in TypeCheckASTNodeAtLocRequest 2022-12-08 14:39:15 +01:00
Alex Hoppen
a8dd6819b5 [IDE] Implement completion-like cursor info for ValueDecls
This brings up the ability to compute cursor info results using the completion-like type checking paradigm, which an reuse ASTContexts and doesn’t need to type check the entire file.

For now, the new implementation only supports cursor info on `ValueDecl`s (not on references) because they were easiest to implement. More cursor info kinds are coming soon.

At the moment, we only run the new implementation in a verification mode: It is only invoked in assert toolchains and when run, we check that the results are equivalent to the old implementation. Once more cursor info kinds are implemented and if the SourceKit stress tester doesn’t find any verification issues, we can enable the new implementation, falling back to the old implementation if the new one didn’t produce any results.
2022-12-08 14:39:14 +01:00
Rintaro Ishizaki
7ab18ff8ce Merge pull request #42545 from jsoref/spelling-sourcekit
Spelling sourcekit
2022-09-22 16:26:17 -07:00
Anthony Latsis
ccb2e047bd Merge pull request #60951 from AnthonyLatsis/migrate-test-suite-to-gh-issues-22
Gardening: Migrate test suite to GH issues p. 22
2022-09-22 20:21:31 +03:00
Anthony Latsis
a8b83b4e06 Gardening: Migrate test suite to GH issues: SourceKit 2022-09-22 03:21:39 +03:00
QuietMisdreavus
4413cee7bf don't use null types when determining extension access level (#61227)
rdar://100169094

Co-authored-by: Max Obermeier <themomax@icloud.com>
2022-09-21 14:19:04 -06:00
Josh Soref
436484c8c8 Gardening: Fix spelling mistakes in */SourceKit
* about
* and
* answering
* because
* before
* cancellation
* clear
* comment
* complete
* corresponding
* cursor
* custom
* dependencies
* doesn't
* expression
* extension
* immediately
* implementation
* implicit
* innovation
* intentionally
* occasionally
* oldest
* parameter
* property
* response
* reuseastcontext
* snapshot
* sourcekit_swift_runtime_link_flags
* synchronously
* target
* that
* unlabeled
* usefulness
* work

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-21 02:03:25 -04:00
Alex Hoppen
b6377ff54a Merge pull request #60765 from ahoppen/pr/rdar98623438
[SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled
2022-08-27 00:36:32 +02:00
Alex Hoppen
c8a7e55f6a [SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled
`typealias` is currently allowed to refer to a protocol without the `any` keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be `any` types.

Implement a SourceKit-specific minimal workaround for that problem by not computing USRs for parameterized protocols.

rdar://98623438
2022-08-26 19:08:06 +02:00
Alex Hoppen
8f421a7e06 [SourceKit] Fix a crash because the API for retrieving intherited protocols of a ProtocolDecl changed
apple/swift#60716 changed `NominalTypeDecl::getAllProtocols` to no longer work on `ProtocolDecl`. Add a new wrapper to Refactoring.cpp that dispatches to either `getInheritedProtocols` or `getAllProtocols` depending on whether the type is a protocol or not.

rdar://99096663
2022-08-24 23:19:31 +02:00
Ben Barham
5c9487286e [CursorInfo] References should not include shadowed declarations
Cursor info on a reference to a decl that shadows other decls should not
include those decls in the secondary symbols. They should only be
added on the decl itself, if that particular location is *also* the
reference to the shadowed decl (eg. in a shorthand if let or closure
capture).

Resolves rdar://96305891.
2022-07-01 13:17:54 -07:00
Richard Wei
94e8f5393e Enable string processing by default.
Make frontend flag `-enable-experimental-string-processing` default to true.
2022-06-12 20:25:16 -07:00
Rintaro Ishizaki
9507315c6b Merge pull request #58973 from rintaro/ide-primaryassociatedtype-rdar93275458
[SourceKit] Update for primary associated types
2022-06-08 11:27:42 -07:00
QuietMisdreavus
5bef9f2118 [SymbolGraphGen] Add filename and module name to symbols' doc comments (#58857)
* move symbol graph samples to the bottom of the file

* add information about a doc comment's file and module

rdar://81190369

* refactor: group file URI collection/serialization together

* test for docComment.module to identify externally-inherited docs
2022-05-24 11:36:13 -06:00
Rintaro Ishizaki
8bda524cd2 [SourceKit] Update for primary associated types
* InterfaceGen reports a primary associated type as a reference to the
  'associatedtype' declaration
* CursorInfo on a primary associated type returns information of the
  'associatedtype' declaration

rdar://93275458
2022-05-18 17:16:49 -07:00
Ben Barham
8889daedce [SourceKit] Add whether a property is dynamic
Properties can also be specified in a protocol/overridden by subclasses,
so they should also be classed as "dynamic" in these cases.

Removed receiver USRs when *not* dynamic, since it's not used for
anything in that case and should be equivalent to the container anyway.

Resolves rdar://92882348.
2022-05-13 15:13:49 -07:00
Alex Hoppen
1843f22066 Merge pull request #58787 from ahoppen/pr/shorthand-closure-info
[CursorInfo] Report values shadowed using shorthand syntax as secondary results
2022-05-13 16:28:47 +02:00
Alex Hoppen
2b364930fc [CursorInfo] Report values shadowed using shorthand syntax as secondary results
When a variable is re-declared using shorthand syntax (`[foo]` closure capture or `if let foo {`), the user doesn’t perceive this as a new variable declaration. Thus, we should return the original declaration as a secondary result.

rdar://91311033
rdar://75455650
2022-05-11 08:05:26 +02:00
Zixu Wang
1ed123e045 [NFC][CursorInfo] Temporarily disable some doc comment check lines
Pull request apple/llvm-project#4442 brings in a change to
`RawComment::getFormattedText` that removes spurious new lines
and whitespaces at the end of block comments. It breaks the
`cursor_symbol_graph_objc` test which is assuming the old behavior.
Temporarily disable the relevant check lines in the test to merge the
llvm change, and then fix the test properly and switch to the new
`getFormattedLines` in SymbolGraphGen.
2022-05-06 10:53:46 -07:00
Ben Barham
680bf2e753 [CursorInfo] Add ObjC location to generated symbol graph
Add the file for an imported ObjC-symbol to the generated symbol graph
when ObjC documentation is requested.

Skips line/column information for now since it's not needed. If we add
those we should extract location retrieval to a common method for both
cursor info and symbol graph gen.

Resolves rdar://91658873.
2022-04-13 14:51:43 -07:00
Ben Barham
e2c9836a1d [CursorInfo] Add Clang documentation to SymbolGraph output
This currently doesn't check for inherited docs, ie. either the
imported declaration has docs or it doesn't. There's also a few odd
cases with mixed doc types and when each line is prefixed with '*', but
it's good enough for an initial implementation.

Moves UTF8 sanitisation out of ASTPrinter.h and into Unicode.h so that
it can be used here as well.

Resolves rdar://91388603.
2022-04-08 13:46:38 -07:00
Ben Barham
15ada41a5a [SourceKit] Make sure to use overlays when reading files
Two paths missed setting up overlays:
  - `CompletionInstance` when checking files from dependencies
  - `SwiftASTManager` when reading in files that it would later replace
    all inputs with

(1) would cause the AST context not to be re-used, even though nothing
had changed. (2) caused all non-completion functionality to fail for any
symbols within files only specified by the overlay.

Resolves rdar://85508213.
2022-03-24 15:30:02 -07:00