Commit Graph

261 Commits

Author SHA1 Message Date
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Ikko Eltociear Ashimine
a1108fffe9 [SourceKit] fix typo in SwiftEditor.cpp
clearning -> clearing
2024-01-16 03:52:03 +09:00
Doug Gregor
b53026d8d4 [Macros] Macro-metaprogram macro roles
Introduce X-macros for the various macro roles, and use them to
macro-metaprogram a lot of boilerplate involved with introducing new
macro roles.
2023-11-13 22:37:54 -08:00
Alex Hoppen
2507e0e9ee [SourceKit] Support getting semantic tokens for macro expansion buffers 2023-10-23 11:06:49 -07:00
Alex Hoppen
4bc03f8392 [SourceKit] Add a request to get the semantic tokens of a file
We need this request for semantic highlighting in LSP. Previously, we were getting the semantic tokens using a 0,0 edit after a document update notification but that will no longer be possible if we open the documents in syntactic only mode.
2023-10-20 10:38:08 -07:00
Hamish Knight
746128c7aa Use StringMap in EditorDiagConsumer
As noted by the comment, storing a `StringRef` is
indeed brittle. Update to use a StringMap.

rdar://111589090
2023-09-15 18:27:49 +01:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Hamish Knight
4ce49bd4d2 [Parse] Sink registerParseRequestFunctions call into ParserUnit 2023-05-22 14:55:18 +01:00
Hamish Knight
62b021030f [SourceKit] Include generated macro buffers in diagnostic responses
Introduce a new key `generated_buffers`, which
stores an array of generated buffers. These
include the buffer text, as well as its original
location and any parent buffers.

While here, also fix rdar://107281079 such that
only apply the filename fallback logic to the
pretty-printed Decl case. We ought to remove this
fallback once the editor can handle it though.

rdar://107281079
rdar://107952288
2023-05-02 16:21:44 +01:00
Hamish Knight
f0d5456b33 NFC: Move some code around 2023-05-02 16:21:44 +01:00
Alex Hoppen
aef35b917e [SourceKit] Expand editor placeholder to trailing closures inside a TryExpr
rdar://108391690
2023-04-21 17:21:50 -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
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -08:00
Doug Gregor
7a1c558899 Add more missing ASTWalker macro behavior entries 2023-02-28 19:13:02 -08:00
Ben Barham
0c3f538822 [AST] Allow ignoring macro expansions
Various requests expect to be walking over the current source file.
While we could add checks to all these to skip decls outside of the
current buffer, it's a little nicer to handle this during the walk
instead.

Allow ignoring nodes that are from macro expansions and add that flag to
the various walks that expect it.

Also add a new `getOriginalAttrs` that filters out attributes in
generated source.
2023-02-16 18:04:56 -08:00
Doug Gregor
b87dfdf2ae Don't annotatae entities not in the primary buffer 2023-02-12 21:42:36 -08:00
Doug Gregor
642d0e9d36 [SourceKit] Disable optimization that's now incorrect with macros.
No test case at the moment, but it's pretty crashy here in practice :)
2023-02-11 19:56:07 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Doug Gregor
3a172fb892 [Macros] Miscellaneous build fixes for macros. 2022-11-13 17:09:12 -08: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
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Alex Hoppen
1e9eac6c64 [SourceKit] Don’t provide incorrect semantic highlighting of nil in case statements as enum decl element
If a 'nil' literal occurs in a swift-case statment, it gets replaced by a reference to 'Optional.none' in the AST. We want to continue highlighting 'nil' as a keyword and not as an enum element.

Resolves apple/sourcekit-lsp#599
rdar://97961865
2022-08-03 22:42:40 +02:00
Alex Hoppen
190ee6ecc7 [CodeCompletion] Replace includes of CodeCompletion.h by more specific ones 2022-02-23 17:08:26 +01:00
Alex Hoppen
fd72674a57 [Code Completion] Split code completion results into context free part that can be cached and contextual part displayed to the user
This allows makes the distinction between cachable and non-cachable properties cleaner and allows us to more easily compute contextual information (like type relations) for cached items later.
2022-01-27 10:40:47 +01:00
Rintaro Ishizaki
2795a19ed6 Merge pull request #40163 from rintaro/ide-completion-enumbitfield
NFC: [CodeCompletion] Use enums in bit fields as-is
2021-12-21 09:40:00 -08:00
Alex Hoppen
c1542bf80e [SourceKit] Guard static assert by _MSC_VER 2021-12-21 11:56:03 +01:00
Alex Hoppen
22f67e89a6 [SourceKit] Explicitly specify frontend action type when creating compiler invocation
Explicitly specify the frontend action to make sure we aren’t loading thes stdlib if the performed action is syntactic only.
2021-12-13 15:32:08 +01:00
Alex Hoppen
dcbedc65fd [SourceKit] Remove some dupliate computation of realpaths 2021-12-08 15:17:13 +01:00
Rintaro Ishizaki
f17671c4a6 Guard a static assert for MSVC
MSVC doens't pack diffrent underlying int types into a bitfield. e.g.

  struct S {
    int a: 1;
    char b: 1;
    int c: 1;
  };

These fields are considered three sparate bitfields.
2021-12-04 00:19:25 -08:00
Alex Hoppen
ac56bfb34e Merge pull request #40066 from ahoppen/pr/deep-stack
[SourceKit] Use deep stack when parsing in the XPC service
2021-11-15 09:17:03 +01:00
Ben Barham
f6db91e3f9 [SourceKit] Ignore references without a location
A keypath using dynamic member lookup results in various `KeyPathExpr`
that have components with no location. Ignore these and any other
references that have a missing location.

Resolves rdar://85237365
2021-11-10 14:52:46 +10:00
Alex Hoppen
3a96cc7c51 [SourceKit] Use a deep stack to perform syntactic parsing
Othwerise we were performing the syntactic parsing on a background queue that had a reduced stack size which could result in stack overflows.

rdar://84474387
2021-11-09 18:36:09 +01:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Meghana Gupta
f458d9b490 Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag (#39516)
* Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag

This includes a bit in the module format to represent if the module was
compiled with -enable-ossa-modules flag. When compiling a client module
with -enable-ossa-modules flag, all dependent modules are checked for this bit,
if not on, recompilation is triggered with -enable-ossa-modules.

* Updated tests
2021-10-04 18:46:40 -07:00
Alex Hoppen
7d5ee83a61 [SourceKit] Allow explicit cancellation of requests with a cancellation token
The key changes here are
- To keep track of cancellation tokens for all `ScheduledConsumer`s in `SwiftASTManager`
- Generate unique request handles for all incoming requests (`create_request_handle `), use these request handles as cancellation tokens and return them from the `sourcekitd_send_request` methods
- Implement cancellation with `sourcekitd_cancel_request` as the entry point and `SwiftASTManager::cancelASTConsumer` as the termination point

Everything else is just plumbing the cancellation token through the various abstraction layers.

rdar://83391505
2021-09-30 11:45:24 +02:00
Hamish Knight
78d8d09b99 [IDE] Adopt ArgumentList 2021-09-01 18:40:26 +01:00
Ben Barham
f6899eda96 [SourceKit] Suppress oslog_invalid_log_message diagnostic in live issues
The index build skips *all* function bodies, including inlinable. The
`OSLogOptimization` pass expects SIL for inlinable bodies and thus
outputs a spurious diagnostic for live issues when the
`OSLogInterpolation` extension is in a separate module to the log
statement.

Ignore this for now, but we may need to re-evaluate if this becomes a
more widespread problem.

Resolves rdar://79100763
2021-08-06 16:49:43 +10:00
Rintaro Ishizaki
4bf9682085 [SourceKit] Avoid unnecessary parsing in 'open' request
If the client doesn't want anything as the response of editor.open,
avoid parsing the source because it's not necessary.

rdar://77693214
2021-05-21 12:16:34 -07:00
Ben Barham
0f21991f02 [SourceKit] Map line and column using the latest snapshot
During a cursor info request, the resolved offset was mapped to line and
column using the buffer inside `SwiftDocumentSyntaxInfo`.

However, prior to 54683ca607,
`editorReplaceText` was not updating the syntax info. This meant that
snapshots would be more up to date than the buffer in the syntax info,
allowing for the possibility of an invalid offset.

While 54683ca607 would also fix this,
snapshots actually have a `getLineAndColumn` anyway. Use that instead of
grabbing the buffer from syntax info.

Resolves rdar://78161348.
2021-05-21 15:42:33 +10:00
Ben Langmuir
006e78e672 Merge pull request #37320 from fwcd/sourcekit-diagnostic-ids
[SourceKit] Add id and category to diagnostics
2021-05-17 14:25:40 -07:00
Rintaro Ishizaki
54683ca607 [SourceKit] Update SyntaxInfo but with lazy parsing in "edit" request
Previously, if the client requests no information from "edit" request,
the syntax info wasn't updated. But "expand placeholder" request
requires the up-to-date syntax info.

rdar://77665805
2021-05-11 09:46:14 -07:00
fwcd
71a34ff428 Represent diagnostic categories as UIDs in SourceKit (WIP) 2021-05-10 20:38:00 +02:00
fwcd
754d19910e Expose diagnostic category via SourceKit 2021-05-08 19:39:09 +02:00
fwcd
e22d26a161 Attach diagnostic ids to SourceKit's diagnostics 2021-05-07 17:45:21 +02:00
Ben Barham
f773e980ce [SourceKit/CursorInfo] Include line and column in result
Add line/column in addition to offset so clients need not map it
themselves.
2021-05-01 09:39:15 +10:00
Alex Hoppen
294977534c [libSyntax] Remove incremental JSON transfer option
We were only keeping track of `RawSyntax` node IDs to incrementally transfer a syntax tree via JSON. However, AFAICT the incremental JSON transfer option has been superceeded by `SyntaxParseActions`, which are more efficient.

So, let’s clean up and remove the `RawSyntax` node ID and JSON incremental transfer option.

In places that still need a notion of `RawSyntax` identity (like determining the reused syntax regions), use the `RawSyntax`’s pointer instead of the manually created ID.

In `incr_transfer_round_trip.py` always use the code path that uses the `SyntaxParseActions` and remove the transitional code that was still using the incremental JSON transfer but was never called.
2021-04-07 10:01:34 +02:00
Rintaro Ishizaki
40dc8e1bd4 [sourcekit] Response "edit" immediately if client needs nothing
If the client doesn't want anything as the response of
'editor.replacetext' requests, we don't even need parsing.

rdar://problem/74984613
2021-03-05 13:18:11 -08:00