Skip to content

Commit a946edf

Browse files
authored
Merge pull request #1263 from dart-lang/merge-source_span-package
Merge `package:source_span`
2 parents db47a84 + 42f81f9 commit a946edf

29 files changed

+4597
-0
lines changed

.github/ISSUE_TEMPLATE/source_span.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:source_span"
3+
about: "Create a bug or file a feature request against package:source_span."
4+
labels: "package:source_span"
5+
---

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
- changed-files:
101101
- any-glob-to-any-file: 'pkgs/source_maps/**'
102102

103+
'package:source_span':
104+
- changed-files:
105+
- any-glob-to-any-file: 'pkgs/source_span/**'
106+
103107
'package:unified_analytics':
104108
- changed-files:
105109
- any-glob-to-any-file: 'pkgs/unified_analytics/**'

.github/workflows/source_span.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: package:source_span
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/source_span.yml'
9+
- 'pkgs/source_span/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/source_span.yml'
14+
- 'pkgs/source_span/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/source_span/
25+
26+
jobs:
27+
# Check code formatting and static analysis on a single OS (linux)
28+
# against Dart dev.
29+
analyze:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk: [dev]
35+
steps:
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
37+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- id: install
41+
name: Install dependencies
42+
run: dart pub get
43+
- name: Check formatting
44+
run: dart format --output=none --set-exit-if-changed .
45+
if: always() && steps.install.outcome == 'success'
46+
- name: Analyze code
47+
run: dart analyze --fatal-infos
48+
if: always() && steps.install.outcome == 'success'
49+
50+
# Run tests on a matrix consisting of two dimensions:
51+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
52+
# 2. release channel: dev
53+
test:
54+
needs: analyze
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
# Add macos-latest and/or windows-latest if relevant for this package.
60+
os: [ubuntu-latest]
61+
sdk: [3.1.0, dev]
62+
steps:
63+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
64+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
65+
with:
66+
sdk: ${{ matrix.sdk }}
67+
- id: install
68+
name: Install dependencies
69+
run: dart pub get
70+
- name: Run VM tests
71+
run: dart test --platform vm
72+
if: always() && steps.install.outcome == 'success'
73+
- name: Run Chrome tests
74+
run: dart test --platform chrome
75+
if: always() && steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ don't naturally belong to other topic monorepos (like
3838
| [pub_semver](pkgs/pub_semver/) | Versions and version constraints implementing pub's versioning policy. This is very similar to vanilla semver, with a few corner cases. | [![package issues](https://img.shields.io/badge/package:pub_semver-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Apub_semver) | [![pub package](https://img.shields.io/pub/v/pub_semver.svg)](https://pub.dev/packages/pub_semver) |
3939
| [source_map_stack_trace](pkgs/source_map_stack_trace/) | A package for applying source maps to stack traces. | [![package issues](https://img.shields.io/badge/package:source_map_stack_trace-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_map_stack_trace) | [![pub package](https://img.shields.io/pub/v/source_map_stack_trace.svg)](https://pub.dev/packages/source_map_stack_trace) |
4040
| [source_maps](pkgs/source_maps/) | A library to programmatically manipulate source map files. | [![package issues](https://img.shields.io/badge/package:source_maps-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_maps) | [![pub package](https://img.shields.io/pub/v/source_maps.svg)](https://pub.dev/packages/source_maps) |
41+
| [source_span](pkgs/source_span/) | Provides a standard representation for source code locations and spans. | [![package issues](https://img.shields.io/badge/package:source_span-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Asource_span) | [![pub package](https://img.shields.io/pub/v/source_span.svg)](https://pub.dev/packages/source_span) |
4142
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![package issues](https://img.shields.io/badge/package:unified_analytics-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics) | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
4243

4344
## Publishing automation

pkgs/source_span/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Don’t commit the following directories created by pub.
2+
.buildlog
3+
.dart_tool/
4+
.pub/
5+
build/
6+
packages
7+
.packages
8+
9+
# Or the files created by dart2js.
10+
*.dart.js
11+
*.js_
12+
*.js.deps
13+
*.js.map
14+
15+
# Include when developing application packages.
16+
pubspec.lock

pkgs/source_span/CHANGELOG.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
## 1.10.1
2+
3+
* Require Dart 3.1
4+
* Move to `dart-lang/tools` monorepo.
5+
6+
## 1.10.0
7+
8+
* Add a `SourceFile.codeUnits` property.
9+
* Require Dart 2.18
10+
* Add an API usage example in `example/`.
11+
12+
## 1.9.1
13+
14+
* Properly handle multi-line labels for multi-span highlights.
15+
16+
* Populate the pubspec `repository` field.
17+
18+
## 1.9.0
19+
20+
* Add `SourceSpanWithContextExtension.subspan` that returns a
21+
`SourceSpanWithContext` rather than a plain `SourceSpan`.
22+
23+
## 1.8.2
24+
25+
* Fix a bug where highlighting multiple spans with `null` URLs could cause an
26+
assertion error. Now when multiple spans are passed with `null` URLs, they're
27+
highlighted as though they all come from different source files.
28+
29+
## 1.8.1
30+
31+
* Fix a bug where the URL header for the highlights with multiple files would
32+
get omitted only one span has a non-null URI.
33+
34+
## 1.8.0
35+
36+
* Stable release for null safety.
37+
38+
## 1.7.0
39+
40+
* Add a `SourceSpan.subspan()` extension method which returns a slice of an
41+
existing source span.
42+
43+
## 1.6.0
44+
45+
* Add support for highlighting multiple source spans at once, providing more
46+
context for span-based messages. This is exposed through the new APIs
47+
`SourceSpan.highlightMultiple()` and `SourceSpan.messageMultiple()` (both
48+
extension methods), `MultiSourceSpanException`, and
49+
`MultiSourceSpanFormatException`.
50+
51+
## 1.5.6
52+
53+
* Fix padding around line numbers that are powers of 10 in
54+
`FileSpan.highlight()`.
55+
56+
## 1.5.5
57+
58+
* Fix a bug where `FileSpan.highlight()` would crash for spans that covered a
59+
trailing newline and a single additional empty line.
60+
61+
## 1.5.4
62+
63+
* `FileSpan.highlight()` now properly highlights point spans at the beginning of
64+
lines.
65+
66+
## 1.5.3
67+
68+
* Fix an edge case where `FileSpan.highlight()` would put the highlight
69+
indicator in the wrong position when highlighting a point span after the end
70+
of a file.
71+
72+
## 1.5.2
73+
74+
* `SourceFile.span()` now goes to the end of the file by default, rather than
75+
ending one character before the end of the file. This matches the documented
76+
behavior.
77+
78+
* `FileSpan.context` now includes the full line on which the span appears for
79+
empty spans at the beginning and end of lines.
80+
81+
* Fix an edge case where `FileSpan.highlight()` could crash when highlighting a
82+
span that ended with an empty line.
83+
84+
## 1.5.1
85+
86+
* Produce better source span highlights for multi-line spans that cover the
87+
entire last line of the span, including the newline.
88+
89+
* Produce better source span highlights for spans that contain Windows-style
90+
newlines.
91+
92+
## 1.5.0
93+
94+
* Improve the output of `SourceSpan.highlight()` and `SourceSpan.message()`:
95+
96+
* They now include line numbers.
97+
* They will now print every line of a multiline span.
98+
* They will now use Unicode box-drawing characters by default (this can be
99+
controlled using [`term_glyph.ascii`][]).
100+
101+
[`term_glyph.ascii`]: https://pub.dartlang.org/documentation/term_glyph/latest/term_glyph/ascii.html
102+
103+
## 1.4.1
104+
105+
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
106+
107+
## 1.4.0
108+
109+
* The `new SourceFile()` constructor is deprecated. This constructed a source
110+
file from a string's runes, rather than its code units, which runs counter to
111+
the way Dart handles strings otherwise. The `new StringFile.fromString()`
112+
constructor (see below) should be used instead.
113+
114+
* The `new SourceFile.fromString()` constructor was added. This works like `new
115+
SourceFile()`, except it uses code units rather than runes.
116+
117+
* The current behavior when characters larger than `0xFFFF` are passed to `new
118+
SourceFile.decoded()` is now considered deprecated.
119+
120+
## 1.3.1
121+
122+
* Properly highlight spans for lines that include tabs with
123+
`SourceSpan.highlight()` and `SourceSpan.message()`.
124+
125+
## 1.3.0
126+
127+
* Add `SourceSpan.highlight()`, which returns just the highlighted text that
128+
would be included in `SourceSpan.message()`.
129+
130+
## 1.2.4
131+
132+
* Fix a new strong mode error.
133+
134+
## 1.2.3
135+
136+
* Fix a bug where a point span at the end of a file without a trailing newline
137+
would be printed incorrectly.
138+
139+
## 1.2.2
140+
141+
* Allow `SourceSpanException.message`, `SourceSpanFormatException.source`, and
142+
`SourceSpanWithContext.context` to be overridden in strong mode.
143+
144+
## 1.2.1
145+
146+
* Fix the declared type of `FileSpan.start` and `FileSpan.end`. In 1.2.0 these
147+
were mistakenly changed from `FileLocation` to `SourceLocation`.
148+
149+
## 1.2.0
150+
151+
* **Deprecated:** Extending `SourceLocation` directly is deprecated. Instead,
152+
extend the new `SourceLocationBase` class or mix in the new
153+
`SourceLocationMixin` mixin.
154+
155+
* Dramatically improve the performance of `FileLocation`.
156+
157+
## 1.1.6
158+
159+
* Optimize `getLine()` in `SourceFile` when repeatedly called.
160+
161+
## 1.1.5
162+
163+
* Fixed another case in which `FileSpan.union` could throw an exception for
164+
external implementations of `FileSpan`.
165+
166+
## 1.1.4
167+
168+
* Eliminated dart2js warning about overriding `==`, but not `hashCode`.
169+
170+
## 1.1.3
171+
172+
* `FileSpan.compareTo`, `FileSpan.==`, `FileSpan.union`, and `FileSpan.expand`
173+
no longer throw exceptions for external implementations of `FileSpan`.
174+
175+
* `FileSpan.hashCode` now fully agrees with `FileSpan.==`.
176+
177+
## 1.1.2
178+
179+
* Fixed validation in `SourceSpanWithContext` to allow multiple occurrences of
180+
`text` within `context`.
181+
182+
## 1.1.1
183+
184+
* Fixed `FileSpan`'s context to include the full span text, not just the first
185+
line of it.
186+
187+
## 1.1.0
188+
189+
* Added `SourceSpanWithContext`: a span that also includes the full line of text
190+
that contains the span.
191+
192+
## 1.0.3
193+
194+
* Cleanup equality operator to accept any Object rather than just a
195+
`SourceLocation`.
196+
197+
## 1.0.2
198+
199+
* Avoid unintentionally allocating extra objects for internal `FileSpan`
200+
operations.
201+
202+
* Ensure that `SourceSpan.operator==` works on arbitrary `Object`s.
203+
204+
## 1.0.1
205+
206+
* Use a more compact internal representation for `FileSpan`.
207+
208+
## 1.0.0
209+
210+
This package was extracted from the
211+
[`source_maps`](https://pub.dev/packages/source_maps) package, but the
212+
API has many differences. Among them:
213+
214+
* `Span` has been renamed to `SourceSpan` and `Location` has been renamed to
215+
`SourceLocation` to clarify their purpose and maintain consistency with the
216+
package name. Likewise, `SpanException` is now `SourceSpanException` and
217+
`SpanFormatException` is not `SourceSpanFormatException`.
218+
219+
* `FixedSpan` and `FixedLocation` have been rolled into the `Span` and
220+
`Location` classes, respectively.
221+
222+
* `SourceFile` is more aggressive about validating its arguments. Out-of-bounds
223+
lines, columns, and offsets will now throw errors rather than be silently
224+
clamped.
225+
226+
* `SourceSpan.sourceUrl`, `SourceLocation.sourceUrl`, and `SourceFile.url` now
227+
return `Uri` objects rather than `String`s. The constructors allow either
228+
`String`s or `Uri`s.
229+
230+
* `Span.getLocationMessage` and `SourceFile.getLocationMessage` are now
231+
`SourceSpan.message` and `SourceFile.message`, respectively. Rather than
232+
taking both a `useColor` and a `color` parameter, they now take a single
233+
`color` parameter that controls both whether and which color is used.
234+
235+
* `Span.isIdentifier` has been removed. This property doesn't make sense outside
236+
of a source map context.
237+
238+
* `SourceFileSegment` has been removed. This class wasn't widely used and was
239+
inconsistent in its choice of which parameters were considered relative and
240+
which absolute.

pkgs/source_span/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)