Skip to content

Commit 2556d01

Browse files
bwilkersonCommit Queue
authored andcommitted
Add documentation for code completion
Change-Id: Ic2954ff86e4fa36ea12e96ffebef6d5621137eb5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404522 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 3b76197 commit 2556d01

File tree

3 files changed

+90
-22
lines changed

3 files changed

+90
-22
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Code completion
2+
3+
This document describes how code completion is implemented and how to fix bugs
4+
and extend it.
5+
6+
## Basic operation
7+
8+
Code completion begins with the receipt of either a `completion.getSuggestions2`
9+
request (from the legacy protocol) or a `textDocument/completion` request (from
10+
LSP). When the request is received the appropriate handler is invoked. The
11+
handler will compute a list of completion suggestions and will then translate
12+
the suggestions into the form required by the protocol.
13+
14+
Code completion is supported in `.dart` files as well as in the `pubspec.yaml`,
15+
`analysis_options.yaml`, and `fix_data.yaml` files.
16+
17+
Dart completion suggestions are computed using the `DartCompletionManager` by
18+
invoking either the method `computeSuggestions` (for the legacy protocol) or
19+
`computeFinalizedCandidateSuggestions`. (The legacy protocol will be changed to
20+
use `computeFinalizedCandidateSuggestions` in the near future.)
21+
22+
The completion manager computes suggestions in two "passes".
23+
24+
- The `InScopeCompletionPass` computes suggestions for every appropriate element
25+
whose name is visible in the name scope surrounding the completion location.
26+
27+
- The `NotImportedCompletionPass` computes suggestions for elements that are not
28+
yet visible in the name scope surrounding the completion location. This pass
29+
is skipped if there isn't time left in the `budget` or if there are already
30+
enough suggestions that the not-yet-imported elements wouldn't be sent anyway.
31+
32+
## Maintaining and improving
33+
34+
The easiest way to fix bugs or add support for new features is to start by
35+
writing a test in the directory `test/services/completion/dart/location`. These
36+
tests are grouped based on the location in the grammar at which completion is
37+
being requested.
38+
39+
When you have a test that's failing, add a breakpoint to
40+
`InScopeCompletionPass.computeSuggestions`. When the debugger stops at the
41+
breakpoint, hover over `_completionNode` to see what kind of node will be
42+
visited. Add a breakpoint in the corresponding visit method and resume
43+
execution. (If the visit method if it doesn't already exist, then add it and
44+
restart the debugger).
45+
46+
## New language features
47+
48+
If a new language feature is being introduced that adds new syntax, then code
49+
completion support will need to be updated. If the changes are limited to
50+
updating an existing node then you should be able to use the method above to
51+
update the corresponding visit method. If the changes required the addition of
52+
some new subclasses of `AstNode`, then you'll likely need to add a new visit
53+
method for the added nodes.

pkg/analysis_server/doc/implementation/overview.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@
33
This section of the documentation discusses how the analysis server works and
44
how to enhance the various features provided by the server.
55

6+
## Design
7+
8+
The design of the analysis server beings with [a description of what the server
9+
does on startup](startup.md)
10+
11+
## Features
12+
613
To learn how the server implements support for a specific feature, read one of
714
the following feature-specific documents:
8-
- Call Hierarchy
9-
- Closing Labels
10-
- Code Completion
11-
- Code Folding
15+
16+
- Call hierarchy
17+
- Closing labels
18+
- [Code completion](code_completion.md)
19+
- Code folding
1220
- documentSymbol
13-
- Flutter Outline
21+
- Flutter outline
1422
- Hovers
15-
- Implemented Markers
23+
- Implemented markers
1624
- [Navigation](navigation.md)
1725
- Occurrences
18-
- Organize Imports
26+
- Organize imports
1927
- Outline
20-
- Overrides Markers
21-
- [Quick Assists](quick_assist.md)
22-
- [Quick Fixes](quick_fix.md)
28+
- Overrides markers
29+
- [Quick assists](quick_assist.md)
30+
- [Quick fixes](quick_fix.md)
2331
- Refactorings - legacy
2432
- Refactorings - self describing
25-
- Search - Find References
26-
- Search - Member Declarations
27-
- Search - Member References
28-
- Search - Top-level Declarations
33+
- Search - Find references
34+
- Search - Member declarations
35+
- Search - Member references
36+
- Search - Top-level declarations
2937
- selectionRange
30-
- Semantic Highlights
38+
- [Semantic highlights](semantic_highlighting.md)
3139
- signatureHelp
32-
- Sort Members
33-
- Type Hierarchy
40+
- Sort members
41+
- Type hierarchy
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# Introduction
22

3-
The `analysis_server` package implements the analysis server, which supports
4-
both the IDE experience and several command-line tools. This directory contains
5-
documentation related to the`analysis_server` package.
3+
The `analysis_server` package implements the Dart Analysis Server (sometimes
4+
referred to as DAS). The analysis server supports both the IDE experience and
5+
command-line tools such as `dart analyze` and `dart fix`.
6+
7+
This directory contains documentation related to the `analysis_server` package.
8+
9+
## Organization
610

711
The documentation is divided into the following sections:
812

913
- [implementation](implementation/overview.md), which describes the
1014
implementation of the server. It is intended to help you understand how the
1115
server works and how to enhance the various features provided by the server.
1216

13-
- [process](process/overview.md), which describes the process that should be
14-
followed when working on the analysis server code base.
17+
- [process](process/overview.md), which describes the processes that should be
18+
followed when working on the analysis server code base.
19+
20+
- [tutorial](tutorial/instrumentation.md), which provides end-user information
21+
about the analysis server.

0 commit comments

Comments
 (0)