Commit Graph

75 Commits

Author SHA1 Message Date
Louis D'hauwe
876682fb12 [SourceKit] Add "Active Regions" request
`source.request.activeregions` is a new request that reports all
`#if`, `#else` and `#elseif` decls in the response with an `is_active` flag.
This is mainly useful for a client to know which branches are active,
but for completeness sake, the active decls are also reported.

Note: it only reports the positions of the decls, not the entire ranges.
It's up to clients to map this to the syntactic structure of a tree.
Reporting the ranges of the decls could be confusing in the case
of nested `#if`s, where the ranges can overlap.
2023-03-01 14:13:58 -08: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
7811519152 [SourceKit] Only verify the solver-based cursor info implementation if requested
This allows us to mark expected deviations between the AST-based and the solver-based implementation in the stress tester as XFails without breaking actual clients

We always verify if a cursor info request is issued through `sourcekitd-test`.
2023-01-31 21:25:51 +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
Sam Kortekaas
0efc3ea745 [SourceKit] Add option for returning fully qualified types in expression type request 2022-09-27 14:13:10 +02:00
Alex Hoppen
a7dcd4604e [SourceKit] Add an operator syntax kind
This will allow us to do semantic highlighting for operators in SourceKit-LSP.
2022-07-25 07:19:49 +02:00
Rintaro Ishizaki
6bbc651f39 [SourceKit] Report comment tags in 'indexsource' request
Comment tags weren't handled at all in SourceKit's 'request.indexsource'
request.

rdar://88728047
2022-03-04 16:14:22 -08:00
Rintaro Ishizaki
d9011e06b2 [CodeCompletion] Add a symbol kind for actors
rdar://79733313
2022-02-15 13:14:46 -08:00
Rintaro Ishizaki
7c92a8e555 [SourceKit] Add a request to generate object files in SourceKit
Add 'request.compile'
2021-12-21 14:35:38 -08:00
Ben Barham
fd7d59daa6 [CursorInfo] Add a synthesized field
Mark implicit declarations with a `synthesized` field, since while we
still want them to have a cursor info result (eg. for their USR to find
possible overrides), it's likely that clients will want to treat them
differently to results that have a real location in source.

An alternative could be to remove the location entirely, but:
  - the module name would also have to be removed to prevent wasted
    lookups in the generated interface
  - having the location could still be useful as the location that
    caused the synthesized declaration (though at the moment only
    synthesized initializers have a location)

Resolves rdar://84990655
2021-11-05 15:52:10 +10:00
Alex Hoppen
2f19d1847f [SourceKit] Add a dedicated request to retrieve the diagnostics of a file
Currently, SourceKit always implicitly sends diagnostics to the client after every edit. This doesn’t match our new cancellation story because diagnostics retrieval is no request and thus can’t be cancelled.

Instead, diagnostics retrieval should be a standalone request, which returns a cancellation token like every other request and which can thus also be cancelled as such.

The indented transition path here is to change all open and edit requests to be syntactic only. When diagnostics are needed, the new diagnostics request should be used.

rdar://83391522
2021-10-13 21:28:18 +02:00
Alex Hoppen
fa0ead5dc1 [SourceKit] Add option to simulate a long-running request
This allows us to remove the dependency on a slow-to-typecheck example for a `sourcekitd-test`.
2021-10-04 21:43:53 +02:00
Fredrik Wieczerkowski
2703d08877 Add CollectVariableType request to SourceKit
- Add VariableTypeCollector
  This new SourceEntityWalker collects types from variable declarations.
- Add SwiftLangSupport::collectVariableTypes
- Implement CollectVariableType request
- Provide information about explicit types in CollectVarType
- Fix HasExplicitType in VariableTypeArray
- Fix typo
- Implement ranged CollectVariableTypes requests
- Use offset/length params for CollectVariableType in sourcekitd-test
- Address a bunch of PR suggestions
- Remove CanonicalType from VariableTypeCollector
  This turned out not to be needed (for now).
- Improve doc comment on VariableTypeCollector::getTypeOffsets
- Remove unused CanonicalTy variable
- Remove out-of-date comment
- Run clang-format on the CollectVariableType implementation
- Fix some minor style issues
- Use emplace_back while collecting variable infos
- Pass CollectVariableType range to VariableTypeCollector
- Use capitalized variable names in VariableTypeArray
  ...as recommended by the LLVM coding standards
- Use PrintOptions for type printing in VariableTypeCollector
- Return void for collectVariableType
  This seems to be cleaner stylistically.
- Avoid visiting subranges of invalid range in VariableTypeCollector
- Use std::string for type buffer in VariableTypeCollectorASTConsumer
- Use plural for PrintedType in VariableTypeArray
- Remove unused fields in VariableTypeArrayBuilder
- Add suggested doc comments to VariableTypeArray
- Remove unused VariableTypeInfo.TypeLength
- Fix typo of ostream in VariableTypeCollectorASTConsumer
- Fix typo
- Document Offset and Length semantics in collectVariableTypes
2021-06-21 19:28:29 +02:00
Alex Hoppen
80d3dedb08 Merge pull request #37450 from ahoppen/pr/count-instructions-for-completion-request
[SourceKit] Report number of instructions executed since SourceKit was started in statistics request
2021-05-25 08:39:43 +02:00
Alex Hoppen
e8b5bcac1d [SourceKit] Report number of instructions executed since SourceKit was started in statistics request
This can be used to measure how many instructions a request executes by retrieving the number of instructions executed since the process’s start before and after executing the request.
2021-05-20 16:30:28 +02:00
fwcd
71a34ff428 Represent diagnostic categories as UIDs in SourceKit (WIP) 2021-05-10 20:38:00 +02:00
fwcd
f6ba1314d0 Add ID field to SourceKit's diagnostics 2021-05-07 17:45:21 +02: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
Nathan Hawes
08250f058a [SourceKit/CursorInfo] Report the set of decls referenced in the symbol graph's "declarationFragments" field.
Resolves rdar://75809521
2021-04-03 09:42:54 +10:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
Ben Barham
19f23130d0 [SourceKit/CursorInfo] Mark dynamic calls
Adds two new fields to the cursor info response:
  1. is_dynamic: whether a call is dynamic
  2. receivers: receivers of the call (USRs)

Users of the CursorInfo request can use "is_dynamic" to decide whether
to lookup overrides or not, and then the "receivers" as the starting
point of the lookup.

Resolves rdar://75385900
2021-03-20 13:57:01 +10:00
Nathan Hawes
e1a4c5f846 [SourceKit][CursorInfo] Add a field for the source language the symbol was originally defined in
Resolves rdar://75446903
2021-03-18 18:49:25 +10:00
Argyrios Kyrtzidis
9ef86bd110 Merge pull request #35873 from nathawes/cursor-info-parent-usrs
[SourceKit][SymbolGraph] Add a 'parent_contexts' field the CursorInfo response
2021-02-11 21:24:01 -08:00
Nathan Hawes
6d940951ca [SourceKit][SymbolGraph] Add a 'ParentContexts' field the CursorInfo response
When the SymbolGraph json is requested via (key.retrieve_symbol_graph: 1) this adds
a new field in the response that lists all the parent contexts of the symbol under
the cursor with their symbol graph kind and name, and their USR:

key.parent_contexts: [
    {
      key.kind: "swift.struct",
      key.name: "Parent",
      key.usr: "s:27cursor_symbol_graph_parents6ParentV"
    },
    ...
  ]
}

Resolves rdar://problem/73904365
2021-02-10 16:35:57 +10:00
Rintaro Ishizaki
27dc2cf406 [SourceKit] Add a request kind to notify dependencies are updated 2021-02-05 18:41:26 -08:00
Ben Barham
6544ba163e [SourceKit/DocSupport] Add a field to mark functions that are async
Resolves rdar://72444843
2021-02-03 15:56:21 +10:00
Alex Hoppen
bfe0a00551 Merge pull request #35429 from ahoppen/remove-bytetree
Remove ByteTree serialization format
2021-01-15 09:28:19 +01:00
Alex Hoppen
8ec8516893 Remove ByteTree serialization format
It was originally designed for faster trasmission of syntax trees from
C++ to SwiftSyntax, but superceded by the CLibParseActions. There's no
deserializer for it anymore, so let's just remove it.
2021-01-14 20:37:49 +01:00
Rintaro Ishizaki
4286c44e72 [CodeCompletion/SourceKit] Consolidate some chunk kinds
Consolidate ThrowsKeyword, RethrowsKeyword, and AsyncKeyword to
EffectsSpecifierKeyword.
Abolish 'key.throwsoffset' and 'key.throwslength' as they aren't used.
2020-12-14 12:25:30 -08:00
Nathan Hawes
388052b6ab [SymbolGraph][CursorInfo] Add option to SourceKit's CursorInfo request to include the SymbolGraph JSON
Adds a new 'key.retrieve_symbol_graph' option to the request. When set to 1 it
includes the JSON for a SymbolGraph containing a single node for the symbol at
the requested position.

This also extends the SymbolGraph library with a new entry point to get a graph
for a single symbol, and to additionally support type substitution to match the
existing CursorInfo behavior (e.g. so that when invoked on `first` in
`Array<Int>().first`, the type is given as `Int?` rather than `Element?`).

Resolves rdar://problem/70551509
2020-12-12 14:38:41 +10:00
Rintaro Ishizaki
77b4f75608 [SourceKit] Reorgantize code completion options
* Abolish 'reuseastcontext' per-request option
* Add 'MaxASTContextReuseCount' global configuration
2020-09-03 19:30:05 -07:00
Rintaro Ishizaki
33336dfb45 [SouceKit] Make "ASTContext reusing" optional
for 'ConformingMethodList' and 'TypeContextInfo'
2020-06-29 15:09:42 -07:00
Bruno Rocha
f000639cce Improve tests and generate the rest of the output 2020-05-29 18:59:25 +02:00
Bruno Rocha
2a48e19ff0 [SourceKit] Add Effective Scope to Index 2020-05-29 18:59:25 +02:00
David Goldman
67a2fe494a Fix up compile operation kind
- `key.compile_operation` instead of `key.compileoperation`
- Make the operation kind optional (nothing emitted for perform sema)
2020-05-18 13:18:40 -04:00
David Goldman
40759df737 [SourceKit] Include operation kind in compile notifications
- Compile will start / did finish now includes the operation
  kind (perform sema or code complete).
- See also
  https://forums.swift.org/t/sourcekit-lsp-file-status-ux/35947
2020-05-15 17:16:30 -04:00
Rintaro Ishizaki
7086ffb79f [CodeCompletion] Annotated result type
Introduced 'TypeAnnotationBegin' chunk kind for grouping the result type
name chunks.

rdar://problem/62617558
2020-05-11 22:56:22 -07:00
Rintaro Ishizaki
05a87e86c4 [CodeCompletion] Give up fast-completion if dependent files are modified
Check if dependencies are modified since the last checking.
Dependencies:

 - Other source files in the current module
 - Dependent files collected by the dependency tracker

When:

 - If the last dependency check was over N (defaults to 5) seconds ago

Invalidate if:

 - The dependency file is missing
 - The modification time of the dependecy is greater than the last check
 - If the modification time is zero, compare the content using the file
   system from the previous completion and the current completion

rdar://problem/62336432
2020-05-04 13:02:09 -07:00
Rintaro Ishizaki
4870d1c017 [SourceKit] Don't use diagnostics to indicate fast-completion
Add 'key.reusingastcontext: 1' to the response instead.
Using diagnostics can be a noise to indexing log clients.

rdar://problem/61367416
2020-04-07 16:26:00 -07:00
Nathan Hawes
9aafadd090 [SourceKit/DocSupport] Report the required bystander modules on symbols from cross-import overlays.
Resolves rdar://problem/59446044
2020-03-24 10:31:08 -07:00
Owen Voorhees
f11df3ee22 [Diagnostics][SourceKit] Expose diagnostic educational notes through SourceKit requests 2020-02-26 14:30:28 -08:00
Rintaro Ishizaki
1e74c39956 [SourceKit] Expose ExpectedTypeRelation for the completion results
So that clients can sort the results using this.

rdar://problem/59066560
2020-02-03 15:57:43 -08:00
Nathan Hawes
b9d5672ca1 [SourceKit] Add a global-configuration request to control SourceKit's behavior around .swiftsourceinfo files
SwiftSourceInfo files provide source location information for decls coming from
loaded modules. For most IDE use cases it either has an undesirable impact on
performance with no benefit (code completion), results in stale locations being
used instead of more up-to-date indexer locations (cursor info), or has no
observable effect (live diagnostics, which are filtered to just those with a
location in the primary file).

For non-IDE clients of SourceKit though, cursor info providing declaration
locations for symbols from other modules is useful, so add a global
configuration option (and a new request to set it) to control whether
.swiftsourceinfo files are loaded or not based on use case (they are loaded by
default).
2019-12-03 13:15:20 -08:00
Ben Langmuir
8784a7b96d Migrate to OptionsDictionary to pass arguments to FileSystemProvider 2019-07-16 10:19:24 -07:00
Marc Rasi
ed3a8ec6fc change it to use a FileSystemProvider selected by the request 2019-07-16 10:19:24 -07:00
Xi Ge
ff32d5899a SourceKit/ExpressionType: allow users to canonicalize collected expression types
The default response of the expression type request doesn't canonicalize expression
types. This patch adds a flag to allow users to canonicalize them.
2019-06-28 11:36:44 -07:00
David Goldman
1b1756cb55 Add InternalDiagnostic to CursorInfoData and NameTranslatingInfo 2019-05-28 04:24:25 -04:00
Joe Groff
7d54810b92 Revert "[SourceKit] Fail requests when an error occurs" 2019-05-22 15:18:28 -07:00
David Goldman
a3a4d2d22b Add InternalDiagnostic to CursorInfoData and NameTranslatingInfo 2019-05-03 11:01:22 -04:00