Skip to content

Commit

Permalink
Merge pull request #1263 from dart-lang/merge-source_span-package
Browse files Browse the repository at this point in the history
Merge `package:source_span`
  • Loading branch information
mosuem authored Dec 11, 2024
2 parents db47a84 + 42f81f9 commit a946edf
Show file tree
Hide file tree
Showing 29 changed files with 4,597 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/source_span.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:source_span"
about: "Create a bug or file a feature request against package:source_span."
labels: "package:source_span"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/source_maps/**'

'package:source_span':
- changed-files:
- any-glob-to-any-file: 'pkgs/source_span/**'

'package:unified_analytics':
- changed-files:
- any-glob-to-any-file: 'pkgs/unified_analytics/**'
75 changes: 75 additions & 0 deletions .github/workflows/source_span.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: package:source_span

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
paths:
- '.github/workflows/source_span.yml'
- 'pkgs/source_span/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/source_span.yml'
- 'pkgs/source_span/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github


defaults:
run:
working-directory: pkgs/source_span/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [3.1.0, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ don't naturally belong to other topic monorepos (like
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |

## Publishing automation
Expand Down
16 changes: 16 additions & 0 deletions pkgs/source_span/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Don’t commit the following directories created by pub.
.buildlog
.dart_tool/
.pub/
build/
packages
.packages

# Or the files created by dart2js.
*.dart.js
*.js_
*.js.deps
*.js.map

# Include when developing application packages.
pubspec.lock
240 changes: 240 additions & 0 deletions pkgs/source_span/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
## 1.10.1

* Require Dart 3.1
* Move to `dart-lang/tools` monorepo.

## 1.10.0

* Add a `SourceFile.codeUnits` property.
* Require Dart 2.18
* Add an API usage example in `example/`.

## 1.9.1

* Properly handle multi-line labels for multi-span highlights.

* Populate the pubspec `repository` field.

## 1.9.0

* Add `SourceSpanWithContextExtension.subspan` that returns a
`SourceSpanWithContext` rather than a plain `SourceSpan`.

## 1.8.2

* Fix a bug where highlighting multiple spans with `null` URLs could cause an
assertion error. Now when multiple spans are passed with `null` URLs, they're
highlighted as though they all come from different source files.

## 1.8.1

* Fix a bug where the URL header for the highlights with multiple files would
get omitted only one span has a non-null URI.

## 1.8.0

* Stable release for null safety.

## 1.7.0

* Add a `SourceSpan.subspan()` extension method which returns a slice of an
existing source span.

## 1.6.0

* Add support for highlighting multiple source spans at once, providing more
context for span-based messages. This is exposed through the new APIs
`SourceSpan.highlightMultiple()` and `SourceSpan.messageMultiple()` (both
extension methods), `MultiSourceSpanException`, and
`MultiSourceSpanFormatException`.

## 1.5.6

* Fix padding around line numbers that are powers of 10 in
`FileSpan.highlight()`.

## 1.5.5

* Fix a bug where `FileSpan.highlight()` would crash for spans that covered a
trailing newline and a single additional empty line.

## 1.5.4

* `FileSpan.highlight()` now properly highlights point spans at the beginning of
lines.

## 1.5.3

* Fix an edge case where `FileSpan.highlight()` would put the highlight
indicator in the wrong position when highlighting a point span after the end
of a file.

## 1.5.2

* `SourceFile.span()` now goes to the end of the file by default, rather than
ending one character before the end of the file. This matches the documented
behavior.

* `FileSpan.context` now includes the full line on which the span appears for
empty spans at the beginning and end of lines.

* Fix an edge case where `FileSpan.highlight()` could crash when highlighting a
span that ended with an empty line.

## 1.5.1

* Produce better source span highlights for multi-line spans that cover the
entire last line of the span, including the newline.

* Produce better source span highlights for spans that contain Windows-style
newlines.

## 1.5.0

* Improve the output of `SourceSpan.highlight()` and `SourceSpan.message()`:

* They now include line numbers.
* They will now print every line of a multiline span.
* They will now use Unicode box-drawing characters by default (this can be
controlled using [`term_glyph.ascii`][]).

[`term_glyph.ascii`]: https://pub.dartlang.org/documentation/term_glyph/latest/term_glyph/ascii.html

## 1.4.1

* Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 1.4.0

* The `new SourceFile()` constructor is deprecated. This constructed a source
file from a string's runes, rather than its code units, which runs counter to
the way Dart handles strings otherwise. The `new StringFile.fromString()`
constructor (see below) should be used instead.

* The `new SourceFile.fromString()` constructor was added. This works like `new
SourceFile()`, except it uses code units rather than runes.

* The current behavior when characters larger than `0xFFFF` are passed to `new
SourceFile.decoded()` is now considered deprecated.

## 1.3.1

* Properly highlight spans for lines that include tabs with
`SourceSpan.highlight()` and `SourceSpan.message()`.

## 1.3.0

* Add `SourceSpan.highlight()`, which returns just the highlighted text that
would be included in `SourceSpan.message()`.

## 1.2.4

* Fix a new strong mode error.

## 1.2.3

* Fix a bug where a point span at the end of a file without a trailing newline
would be printed incorrectly.

## 1.2.2

* Allow `SourceSpanException.message`, `SourceSpanFormatException.source`, and
`SourceSpanWithContext.context` to be overridden in strong mode.

## 1.2.1

* Fix the declared type of `FileSpan.start` and `FileSpan.end`. In 1.2.0 these
were mistakenly changed from `FileLocation` to `SourceLocation`.

## 1.2.0

* **Deprecated:** Extending `SourceLocation` directly is deprecated. Instead,
extend the new `SourceLocationBase` class or mix in the new
`SourceLocationMixin` mixin.

* Dramatically improve the performance of `FileLocation`.

## 1.1.6

* Optimize `getLine()` in `SourceFile` when repeatedly called.

## 1.1.5

* Fixed another case in which `FileSpan.union` could throw an exception for
external implementations of `FileSpan`.

## 1.1.4

* Eliminated dart2js warning about overriding `==`, but not `hashCode`.

## 1.1.3

* `FileSpan.compareTo`, `FileSpan.==`, `FileSpan.union`, and `FileSpan.expand`
no longer throw exceptions for external implementations of `FileSpan`.

* `FileSpan.hashCode` now fully agrees with `FileSpan.==`.

## 1.1.2

* Fixed validation in `SourceSpanWithContext` to allow multiple occurrences of
`text` within `context`.

## 1.1.1

* Fixed `FileSpan`'s context to include the full span text, not just the first
line of it.

## 1.1.0

* Added `SourceSpanWithContext`: a span that also includes the full line of text
that contains the span.

## 1.0.3

* Cleanup equality operator to accept any Object rather than just a
`SourceLocation`.

## 1.0.2

* Avoid unintentionally allocating extra objects for internal `FileSpan`
operations.

* Ensure that `SourceSpan.operator==` works on arbitrary `Object`s.

## 1.0.1

* Use a more compact internal representation for `FileSpan`.

## 1.0.0

This package was extracted from the
[`source_maps`](https://pub.dev/packages/source_maps) package, but the
API has many differences. Among them:

* `Span` has been renamed to `SourceSpan` and `Location` has been renamed to
`SourceLocation` to clarify their purpose and maintain consistency with the
package name. Likewise, `SpanException` is now `SourceSpanException` and
`SpanFormatException` is not `SourceSpanFormatException`.

* `FixedSpan` and `FixedLocation` have been rolled into the `Span` and
`Location` classes, respectively.

* `SourceFile` is more aggressive about validating its arguments. Out-of-bounds
lines, columns, and offsets will now throw errors rather than be silently
clamped.

* `SourceSpan.sourceUrl`, `SourceLocation.sourceUrl`, and `SourceFile.url` now
return `Uri` objects rather than `String`s. The constructors allow either
`String`s or `Uri`s.

* `Span.getLocationMessage` and `SourceFile.getLocationMessage` are now
`SourceSpan.message` and `SourceFile.message`, respectively. Rather than
taking both a `useColor` and a `color` parameter, they now take a single
`color` parameter that controls both whether and which color is used.

* `Span.isIdentifier` has been removed. This property doesn't make sense outside
of a source map context.

* `SourceFileSegment` has been removed. This class wasn't widely used and was
inconsistent in its choice of which parameters were considered relative and
which absolute.
27 changes: 27 additions & 0 deletions pkgs/source_span/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2014, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit a946edf

Please sign in to comment.