skyward-core 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/skyward/core/diagnostics/excerpt.rb +52 -0
- data/lib/skyward/core/diagnostics/spots.rb +177 -0
- data/lib/skyward/core/diagnostics/suggestion.rb +13 -0
- data/lib/skyward/core/diagnostics.rb +11 -0
- data/lib/skyward/core/signatures/loader.rb +28 -5
- data/lib/skyward/core/types/reader.rb +63 -11
- data/lib/skyward/core/types.rb +9 -3
- data/lib/skyward/core/version.rb +1 -1
- data/sig/generated/skyward/core/diagnostics/excerpt.rbs +27 -0
- data/sig/generated/skyward/core/diagnostics/spots.rbs +101 -0
- data/sig/generated/skyward/core/diagnostics/suggestion.rbs +8 -0
- data/sig/generated/skyward/core/diagnostics.rbs +21 -0
- data/sig/generated/skyward/core/signatures/loader.rbs +11 -0
- data/sig/generated/skyward/core/types/reader.rbs +23 -4
- data/sig/generated/skyward/core/types.rbs +21 -6
- data/sig/manual/skyward/core/diagnostics/excerpt.rbs +3 -0
- data/sig/manual/skyward/core/diagnostics/spots.rbs +3 -0
- data/sig/manual/skyward/core/diagnostics/suggestion.rbs +3 -0
- metadata +26 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e3fd98462e9c708fda03399e73fd8ecfdd78377ac8e627c1b932b91a6f8a28d7
|
|
4
|
+
data.tar.gz: 3eefa7cd5299ef5ab7eec622619ea731fa5684e97bdf8c4d9b15ac757a5951fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1df469b179dbedd31e0736b436f5aeaebcc560e662a43ba46a8424e69b6bdd759a00c84801bd0ccb22b2d85ae1a561c0d9df5568c50466e6e1e562a01ef86d9b
|
|
7
|
+
data.tar.gz: bf50ced3df262eb2b0d45a93592e5147d32ea0862cfe392b9ba9d50f1b7bb8e152e9ea8d161df68ea85b7a30004b398ea807b80312e6196689782a20fd70fd09
|
data/README.md
CHANGED
|
@@ -13,6 +13,7 @@ The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../s
|
|
|
13
13
|
- **Keeping `sig/generated` current.** One function regenerates your app's `sig/generated` from its Ruby with rbs-inline, and the Skyward commands that read types call it first, so you never run rbs-inline by hand. `skyward check` only checks it's current, for CI.
|
|
14
14
|
- **Reading RBS types.** One reader turns a signature into values that Skyward API and Skyward ORM each build their own mappings on, so a `Todo` read from the database and a `Todo` sent as JSON are the same thing.
|
|
15
15
|
- **`Skyward::Core::BootError`**, which every Skyward gem raises when your app can't boot, saying why.
|
|
16
|
+
- **Pointing a boot error at its source.** A boot error about your Ruby or RBS shows an excerpt of the file, with a `path:line` header and carets under the problem, and a "Did you mean" suggestion for a misspelt name, rendered the same way by every Skyward gem.
|
|
16
17
|
|
|
17
18
|
## Adding commands
|
|
18
19
|
|
|
@@ -35,7 +36,8 @@ Skyward supports every Ruby that isn't end-of-life (3.3 and later, as of Novembe
|
|
|
35
36
|
This README is the spec, and this section lists each part of it that's built, as it lands. The gem opens the `Skyward` namespace and sets up its loader.
|
|
36
37
|
|
|
37
38
|
- **The `skyward` command.** The executable loads each installed gem's `commands.rb`, `Skyward::Core::CLI.register` adds a command, and `skyward` lists them and runs one, as [Adding commands](#adding-commands) describes. For the commands to run other gems' executables, `Skyward::Core::CLI::Executable.find(name, feature: name)` returns the path of gem `name`'s executable `name` when `feature` can be required in the bundle `skyward` runs in, or `nil` otherwise, and `Skyward::Core::CLI::Executable::CAPTURE` runs a command with an environment in a directory and returns its output, errors included, and whether it succeeded.
|
|
38
|
-
- **Loading RBS signatures.** `Skyward::Core::Signatures.load(directory)` returns an `RBS::DefinitionBuilder` over every `.rbs` file under `directory`, the `sig/` of each Skyward gem that has registered it with `Skyward::Core::Signatures.register(path)`, and the `date` and `
|
|
39
|
+
- **Loading RBS signatures.** `Skyward::Core::Signatures.load(directory)` returns an `RBS::DefinitionBuilder` over every `.rbs` file under `directory`, the `sig/` of each Skyward gem that has registered it with `Skyward::Core::Signatures.register(path)`, and the `date`, `time` and `bigdecimal` libraries. Skyward Core registers its own. A directory that doesn't exist contributes nothing. A file that doesn't parse, a name declared twice, or a class whose declarations disagree on its type parameters raises `Skyward::Core::BootError` with an excerpt: carets under the token that doesn't parse (`Syntax error: <RBS's message>.`), under each declaration's name (`Todo is declared twice.`), or under the name of the declaration RBS names.
|
|
39
40
|
- **Keeping `sig/generated` current.** `Skyward::Core::Signatures::Inline.generate(directory, rbs_inline:, capture:)` runs the rbs-inline executable at `rbs_inline` through `capture`, in `directory` and in its default opt-in mode, which reads only files marked `# rbs_inline: enabled`, over every `.rb` file there outside `test/`, `spec/`, `vendor/`, `tmp/` and hidden directories, into a scratch directory, as `skyward check` does. It then writes each file whose content differs to `directory`'s `sig/generated`, leaving the others untouched, removes each file there that rbs-inline no longer generates, and any directory that leaves empty, and returns `nil`. When rbs-inline fails, it changes nothing and returns a message with rbs-inline's output, for the command to report. With no `rbs_inline`, as in a bundle without rbs-inline, it runs nothing and returns `nil`, so the app runs with `sig/generated` as committed.
|
|
40
|
-
- **Reading RBS types.** `Skyward::Core::Types::Reader.new(builder)` takes the `RBS::DefinitionBuilder` that `Skyward::Core::Signatures.load` returns, and `read(type)` turns an RBS type into a frozen `Data` value from `Skyward::Core::Types`: a `Scalar` (`:integer`, `:float`, `:string`, `:bool`, `:date`, `:time` or `:untyped`), a `Literal` (a String, Integer, boolean or `nil`), an `Enum` of Symbols, a `Nullable`, an `ArrayOf`, a `HashOf` (a `Hash[String, T]`, of its values' type), a `Record` or `Named` class with `Field`s (a name, a type and whether it's required), or a `
|
|
41
|
+
- **Reading RBS types.** `Skyward::Core::Types::Reader.new(builder, refinements: {})` takes the `RBS::DefinitionBuilder` that `Skyward::Core::Signatures.load` returns, and `read(type)` turns an RBS type into a frozen `Data` value from `Skyward::Core::Types`: a `Scalar` (`:integer`, `:float`, `:string`, `:bool`, `:date`, `:time`, `:decimal` (a `BigDecimal`) or `:untyped`), a `Literal` (a String, Integer, boolean or `nil`), an `Enum` of Symbols, a `Nullable`, an `ArrayOf`, a `HashOf` (a `Hash[String, T]`, of its values' type), a `Record` or `Named` class with `Field`s (a name, a type and whether it's required), a `Union`, or a `Refined`. It expands aliases, generic ones included, reads `T?` and `T | nil` as `Nullable` and a union of symbol literals as one `Enum`, and flattens nested unions, dropping duplicates. `refinements:` maps an alias's full name (`"::Skyward::ORM::uuid"`) to a Symbol (`:uuid`), so a gem can tell which alias a type was written with: an alias in it reads as a `Refined` of what the alias expands to (`type`) and that Symbol (`as`), wherever it's reached, directly, through another alias of it, or inside a `T?` (a `Nullable` of the `Refined`), an `Array[T]` or a record. Every other alias, and every alias when `refinements:` is left out, expands to what it names and keeps nothing of it. A class is `Named` when its RBS declares public instance `attr_reader`s, rbs-inline's `Data.define` output included: its fields come from its own declarations, in written order, across every file that reopens it, skipping `private` sections. A type it can't read, such as an interface, a tuple, a proc, a `Hash` whose keys aren't `String`s or a class with no readers, comes back as an `Unreadable` naming the type, the class and reader it was found at (`Todo#tags`), what to use instead, and its `suggestion`: for a class name no loaded signature declares (`attr_reader list: Lisst`), the closest declared class name, and otherwise `nil`, for the caller to raise `Skyward::Core::BootError` with its own context. A class with no loaded Ruby class raises `Skyward::Core::BootError` with an excerpt of its declaration, carets under its name, and a type that refers to itself raises it naming the cycle. `type_name(klass)` finds a Ruby class's RBS declaration (none for an anonymous class), and `method_type(type_name, method)` a method's signature, raising `Skyward::Core::BootError` when RBS can't build the class. When RBS's error has a location, the message is RBS's without it, plus an excerpt, and a type name RBS can't find adds `Did you mean ...?` with the closest declared name of the same kind.
|
|
41
42
|
- **`Skyward::Core::BootError`**, for any Skyward gem to raise when an app can't boot.
|
|
43
|
+
- **Pointing a boot error at its source.** A `Skyward::Core::Diagnostics::Spot` is a file, a line, that line's text, and optionally a range of character columns to put carets under. `Skyward::Core::Diagnostics::Spots.rbs(location)` makes one from an `RBS::Location`, from the buffer RBS keeps in memory. The rest read a Ruby file through Prism, and return `nil` when it can't be read or nothing on the line matches, as when it changed after it loaded. Given a `Method`, `keyword_parameter(method, name)`, `parameters(method)` and `method_name(method)` find its `def` and return a spot under one keyword parameter, the whole parameter list, or its name. Given a file and line, as from `caller_locations`, `keyword_key(path, line, call:, key:)` and `keyword_value(path, line, call:, key:)` find the call named `call` that starts there and return a spot under a keyword argument's key (`lsit_id:`) or value (`:show`), `symbol(path, line, call:, value:)` under a Symbol argument, and `string(path, line, call:, part:)` under a part of a String argument (`:id` in `"/:id"`). `reader_type(path, line)` returns a spot under the type in an `attr_reader`'s `#:` comment. `Skyward::Core::Diagnostics::Excerpt.render(spots)` renders spots, in order, as a block indented four spaces for a message to include, or `nil` with no spot. Each file's spots make a block starting with a `path:line` header naming the first line that has carets, else the first line, with the path relative to the current directory when it's inside it. Its lines follow in line order, with their common leading whitespace removed, `...` between two lines that aren't adjacent, and a line of `^` under each spot's columns. `Skyward::Core::Diagnostics::Suggestion.closest(name, names)` returns the closest of `names` to `name` from Ruby's `DidYouMean::SpellChecker`, or `nil` when none is close, and requires `did_you_mean` itself, so it works under `--disable-did_you_mean`.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics::Excerpt
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
INDENT = " " #: String
|
|
7
|
+
|
|
8
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
9
|
+
# @rbs directory: String
|
|
10
|
+
# @rbs return: String?
|
|
11
|
+
def render(spots, directory: Dir.pwd)
|
|
12
|
+
return if spots.empty?
|
|
13
|
+
|
|
14
|
+
spots.group_by(&:path).map { |path, in_file| block(relative(path, directory), in_file) }.join("\n\n")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# @rbs path: String
|
|
20
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
21
|
+
# @rbs return: String
|
|
22
|
+
def block(path, spots)
|
|
23
|
+
lines = spots.group_by(&:line).sort_by(&:first)
|
|
24
|
+
texts = lines.map { |(_, on_line)| on_line.fetch(0).text }
|
|
25
|
+
indent = texts.reject { |text| text.strip.empty? }.map { |text| text[/\A\s*/].to_s.size }.min || 0
|
|
26
|
+
header = lines.find { |(_, on_line)| on_line.any?(&:columns) } || lines.fetch(0)
|
|
27
|
+
body = lines.each_with_index.flat_map do |(line, on_line), index|
|
|
28
|
+
gap = "..." if index.positive? && lines.fetch(index - 1).first != line - 1
|
|
29
|
+
[gap, texts.fetch(index)[indent..].to_s, *carets(on_line, indent)].compact
|
|
30
|
+
end
|
|
31
|
+
["#{path}:#{header.first}", *body].map { |row| "#{INDENT}#{row}".rstrip }.join("\n")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
35
|
+
# @rbs indent: Integer
|
|
36
|
+
# @rbs return: Array[String]
|
|
37
|
+
def carets(spots, indent)
|
|
38
|
+
columns = spots.flat_map { |spot| spot.columns.to_a }.map { |column| column - indent }
|
|
39
|
+
return [] if columns.empty?
|
|
40
|
+
|
|
41
|
+
[(0..columns.max.to_i).map { |column| columns.include?(column) ? "^" : " " }.join]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs path: String
|
|
45
|
+
# @rbs directory: String
|
|
46
|
+
# @rbs return: String
|
|
47
|
+
def relative(path, directory)
|
|
48
|
+
prefix = File.join(File.expand_path(directory), "")
|
|
49
|
+
expanded = File.expand_path(path, directory)
|
|
50
|
+
expanded.start_with?(prefix) ? expanded.delete_prefix(prefix) : path
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
module Skyward::Core::Diagnostics::Spots
|
|
6
|
+
extend self
|
|
7
|
+
|
|
8
|
+
# @rbs location: RBS::Location[untyped, untyped]
|
|
9
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot
|
|
10
|
+
def rbs(location)
|
|
11
|
+
line = location.start_line
|
|
12
|
+
text = location.buffer.lines.fetch(line - 1, "")
|
|
13
|
+
finish = location.end_line == line ? location.end_column : text.size
|
|
14
|
+
spot(location.buffer.name.to_s, line, text, location.start_column...finish)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @rbs method: Method | UnboundMethod
|
|
18
|
+
# @rbs name: Symbol
|
|
19
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
20
|
+
def keyword_parameter(method, name)
|
|
21
|
+
definition(method) { |node| node.parameters&.keywords&.find { |keyword| keyword.name == name }&.location }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @rbs method: Method | UnboundMethod
|
|
25
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
26
|
+
def parameters(method) = definition(method) { |node| node.parameters&.location }
|
|
27
|
+
|
|
28
|
+
# @rbs method: Method | UnboundMethod
|
|
29
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
30
|
+
def method_name(method) = definition(method, &:name_loc)
|
|
31
|
+
|
|
32
|
+
# @rbs path: String
|
|
33
|
+
# @rbs line: Integer
|
|
34
|
+
# @rbs call: Symbol
|
|
35
|
+
# @rbs key: Symbol
|
|
36
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
37
|
+
def keyword_key(path, line, call:, key:)
|
|
38
|
+
arguments(path, line, call) { |found| pair(found, key)&.key&.location }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @rbs path: String
|
|
42
|
+
# @rbs line: Integer
|
|
43
|
+
# @rbs call: Symbol
|
|
44
|
+
# @rbs key: Symbol
|
|
45
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
46
|
+
def keyword_value(path, line, call:, key:)
|
|
47
|
+
arguments(path, line, call) { |found| pair(found, key)&.value&.location }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @rbs path: String
|
|
51
|
+
# @rbs line: Integer
|
|
52
|
+
# @rbs call: Symbol
|
|
53
|
+
# @rbs value: Symbol
|
|
54
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
55
|
+
def symbol(path, line, call:, value:)
|
|
56
|
+
arguments(path, line, call) do |found|
|
|
57
|
+
found.find { |argument| symbol?(argument, value) }&.location
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @rbs path: String
|
|
62
|
+
# @rbs line: Integer
|
|
63
|
+
# @rbs call: Symbol
|
|
64
|
+
# @rbs part: String
|
|
65
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
66
|
+
def string(path, line, call:, part:)
|
|
67
|
+
arguments(path, line, call) do |found|
|
|
68
|
+
found.filter_map { |argument| within(argument.content_loc, part) if argument.is_a?(Prism::StringNode) }.first
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# @rbs path: String
|
|
73
|
+
# @rbs line: Integer
|
|
74
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
75
|
+
def reader_type(path, line)
|
|
76
|
+
parse(path) do |result|
|
|
77
|
+
next unless call(result, line, :attr_reader)
|
|
78
|
+
|
|
79
|
+
comment = result.comments.find do |found|
|
|
80
|
+
found.location.start_line == line && found.location.slice.start_with?("#:")
|
|
81
|
+
end
|
|
82
|
+
within(comment.location, comment.location.slice.delete_prefix("#:").strip) if comment
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
# @rbs path: String
|
|
89
|
+
# @rbs line: Integer
|
|
90
|
+
# @rbs text: String
|
|
91
|
+
# @rbs columns: Range[Integer]
|
|
92
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot
|
|
93
|
+
def spot(path, line, text, columns)
|
|
94
|
+
# A zero-width location, such as the end of a file, still gets a caret.
|
|
95
|
+
finish = [columns.end, columns.begin + 1].max
|
|
96
|
+
Skyward::Core::Diagnostics::Spot.new(path:, line:, text:, columns: columns.begin...finish)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# @rbs path: String
|
|
100
|
+
# @rbs &: (Prism::ParseResult) -> Prism::Location?
|
|
101
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
102
|
+
def parse(path)
|
|
103
|
+
return unless File.file?(path)
|
|
104
|
+
|
|
105
|
+
source = File.read(path)
|
|
106
|
+
location = yield Prism.parse(source, filepath: path)
|
|
107
|
+
return unless location
|
|
108
|
+
|
|
109
|
+
line = location.start_line
|
|
110
|
+
text = source.lines.fetch(line - 1, "").chomp
|
|
111
|
+
finish = location.end_line == line ? location.end_character_column : text.size
|
|
112
|
+
spot(path, line, text, location.start_character_column...finish)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @rbs method: Method | UnboundMethod
|
|
116
|
+
# @rbs &: (Prism::DefNode) -> Prism::Location?
|
|
117
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
118
|
+
def definition(method)
|
|
119
|
+
path, line = method.source_location
|
|
120
|
+
return unless path && line
|
|
121
|
+
|
|
122
|
+
parse(path) do |result|
|
|
123
|
+
found = result.value.breadth_first_search do |node|
|
|
124
|
+
node.is_a?(Prism::DefNode) && node.name == method.original_name && node.location.start_line == line
|
|
125
|
+
end
|
|
126
|
+
yield found if found.is_a?(Prism::DefNode)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# @rbs path: String
|
|
131
|
+
# @rbs line: Integer
|
|
132
|
+
# @rbs name: Symbol
|
|
133
|
+
# @rbs &: (Array[Prism::node]) -> Prism::Location?
|
|
134
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
135
|
+
def arguments(path, line, name)
|
|
136
|
+
parse(path) do |result|
|
|
137
|
+
found = call(result, line, name)
|
|
138
|
+
yield found.arguments&.arguments || [] if found
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# @rbs result: Prism::ParseResult
|
|
143
|
+
# @rbs line: Integer
|
|
144
|
+
# @rbs name: Symbol
|
|
145
|
+
# @rbs return: Prism::CallNode?
|
|
146
|
+
def call(result, line, name)
|
|
147
|
+
found = result.value.breadth_first_search do |node|
|
|
148
|
+
node.is_a?(Prism::CallNode) && node.name == name && node.location.start_line == line
|
|
149
|
+
end
|
|
150
|
+
found if found.is_a?(Prism::CallNode)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# @rbs arguments: Array[Prism::node]
|
|
154
|
+
# @rbs key: Symbol
|
|
155
|
+
# @rbs return: Prism::AssocNode?
|
|
156
|
+
def pair(arguments, key)
|
|
157
|
+
keywords = arguments.find { |argument| argument.is_a?(Prism::KeywordHashNode) }
|
|
158
|
+
return unless keywords.is_a?(Prism::KeywordHashNode)
|
|
159
|
+
|
|
160
|
+
found = keywords.elements.find { |element| element.is_a?(Prism::AssocNode) && symbol?(element.key, key) }
|
|
161
|
+
found if found.is_a?(Prism::AssocNode)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# @rbs node: Prism::node
|
|
165
|
+
# @rbs value: Symbol
|
|
166
|
+
# @rbs return: bool
|
|
167
|
+
def symbol?(node, value) = node.is_a?(Prism::SymbolNode) && node.unescaped == value.to_s
|
|
168
|
+
|
|
169
|
+
# Prism's locations count bytes, so a part is found by its byte offset.
|
|
170
|
+
# @rbs location: Prism::Location
|
|
171
|
+
# @rbs part: String
|
|
172
|
+
# @rbs return: Prism::Location?
|
|
173
|
+
def within(location, part)
|
|
174
|
+
offset = location.slice.byteindex(part)
|
|
175
|
+
location.copy(start_offset: location.start_offset + offset, length: part.bytesize) if offset
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Ruby run with --disable-did_you_mean doesn't load it.
|
|
4
|
+
require "did_you_mean"
|
|
5
|
+
|
|
6
|
+
module Skyward::Core::Diagnostics::Suggestion
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
# @rbs name: String
|
|
10
|
+
# @rbs names: Array[String]
|
|
11
|
+
# @rbs return: String?
|
|
12
|
+
def closest(name, names) = DidYouMean::SpellChecker.new(dictionary: names).correct(name).first
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics
|
|
4
|
+
# The line's text travels with it, so an excerpt never reads the file again.
|
|
5
|
+
Spot = Data.define(
|
|
6
|
+
:path, #: String
|
|
7
|
+
:line, #: Integer
|
|
8
|
+
:text, #: String
|
|
9
|
+
:columns #: Range[Integer]?
|
|
10
|
+
)
|
|
11
|
+
end
|
|
@@ -21,15 +21,38 @@ class Skyward::Core::Signatures::Loader
|
|
|
21
21
|
def load(directory)
|
|
22
22
|
loader = RBS::EnvironmentLoader.new
|
|
23
23
|
[directory, *@gems].each { |path| loader.add(path: Pathname(path)) }
|
|
24
|
-
%w[date time].each { |library| loader.add(library:, version: nil) }
|
|
24
|
+
%w[date time bigdecimal].each { |library| loader.add(library:, version: nil) }
|
|
25
25
|
env = RBS::Environment.from_loader(loader).resolve_type_names
|
|
26
26
|
# RBS otherwise defers this conflict until a definition is built, past boot.
|
|
27
27
|
env.validate_type_params
|
|
28
28
|
RBS::DefinitionBuilder.new(env:)
|
|
29
|
+
rescue RBS::ParsingError => e
|
|
30
|
+
raise Skyward::Core::BootError, failure("Syntax error: #{e.error_message}.", [e.location])
|
|
29
31
|
rescue RBS::DuplicatedDeclarationError => e
|
|
30
|
-
|
|
31
|
-
raise Skyward::Core::BootError, "
|
|
32
|
-
rescue RBS::
|
|
33
|
-
|
|
32
|
+
names = e.decls.filter_map { |decl| name_location(decl) }
|
|
33
|
+
raise Skyward::Core::BootError, failure("#{e.name.to_s.delete_prefix("::")} is declared twice.", names)
|
|
34
|
+
rescue RBS::GenericParameterMismatchError => e
|
|
35
|
+
location = e.decl.location
|
|
36
|
+
message = e.message.delete_prefix("#{RBS::Location.to_string(location)}: ")
|
|
37
|
+
raise Skyward::Core::BootError, failure(message, [location&.[](:name)].compact)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
# @rbs decl: RBS::DuplicatedDeclarationError::declaration
|
|
43
|
+
# @rbs return: RBS::Location[untyped, untyped]?
|
|
44
|
+
def name_location(decl)
|
|
45
|
+
case decl
|
|
46
|
+
when RBS::AST::Declarations::ClassAlias, RBS::AST::Declarations::ModuleAlias then decl.location&.[](:new_name)
|
|
47
|
+
else decl.location&.[](:name)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @rbs message: String
|
|
52
|
+
# @rbs locations: Array[RBS::Location[untyped, untyped]]
|
|
53
|
+
# @rbs return: String
|
|
54
|
+
def failure(message, locations)
|
|
55
|
+
spots = locations.map { |location| Skyward::Core::Diagnostics::Spots.rbs(location) }
|
|
56
|
+
["Can't load the RBS signatures: #{message}", Skyward::Core::Diagnostics::Excerpt.render(spots)].compact.join("\n\n")
|
|
34
57
|
end
|
|
35
58
|
end
|
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
class Skyward::Core::Types::Reader
|
|
4
4
|
# @rbs @builder: RBS::DefinitionBuilder
|
|
5
|
+
# @rbs @refinements: Hash[String, Symbol]
|
|
5
6
|
|
|
6
7
|
SCALARS = {
|
|
7
8
|
"::Integer" => :integer,
|
|
8
9
|
"::Float" => :float,
|
|
9
10
|
"::String" => :string,
|
|
10
11
|
"::Date" => :date,
|
|
11
|
-
"::Time" => :time
|
|
12
|
+
"::Time" => :time,
|
|
13
|
+
"::BigDecimal" => :decimal
|
|
12
14
|
}.freeze #: Hash[String, Skyward::Core::Types::scalar]
|
|
13
15
|
|
|
14
16
|
NIL_LITERAL = Skyward::Core::Types::Literal.new(value: nil) #: Skyward::Core::Types::Literal
|
|
15
17
|
|
|
16
18
|
# @rbs builder: RBS::DefinitionBuilder
|
|
19
|
+
# @rbs refinements: Hash[String, Symbol]
|
|
17
20
|
# @rbs return: void
|
|
18
|
-
def initialize(builder)
|
|
21
|
+
def initialize(builder, refinements: {})
|
|
19
22
|
@builder = builder
|
|
23
|
+
@refinements = refinements
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
# @rbs type: RBS::Types::t
|
|
@@ -39,11 +43,45 @@ class Skyward::Core::Types::Reader
|
|
|
39
43
|
def method_type(type_name, method_name)
|
|
40
44
|
@builder.build_instance(type_name).methods[method_name]&.method_types&.first
|
|
41
45
|
rescue RBS::DefinitionError => e
|
|
42
|
-
raise Skyward::Core::BootError,
|
|
46
|
+
raise Skyward::Core::BootError, definition_failure(e)
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
private
|
|
46
50
|
|
|
51
|
+
# @rbs error: RBS::DefinitionError
|
|
52
|
+
# @rbs return: String
|
|
53
|
+
def definition_failure(error)
|
|
54
|
+
# Not every RBS error has a location, and those that do share no ancestor.
|
|
55
|
+
location = error.location if error.respond_to?(:location) # steep:ignore NoMethod
|
|
56
|
+
case location
|
|
57
|
+
when RBS::Location
|
|
58
|
+
message = error.message.delete_prefix("#{RBS::Location.to_string(location)}: ")
|
|
59
|
+
suggestion = closest(error.type_name) if error.is_a?(RBS::NoTypeFoundError)
|
|
60
|
+
explain("Can't read the RBS signatures: #{message}", location, suggestion)
|
|
61
|
+
else "Can't read the RBS signatures: #{error.message}"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# @rbs message: String
|
|
66
|
+
# @rbs location: RBS::Location[untyped, untyped]?
|
|
67
|
+
# @rbs suggestion: String?
|
|
68
|
+
# @rbs return: String
|
|
69
|
+
def explain(message, location, suggestion = nil)
|
|
70
|
+
spots = [location].compact.map { |found| Skyward::Core::Diagnostics::Spots.rbs(found) }
|
|
71
|
+
hint = "Did you mean #{suggestion}?" if suggestion
|
|
72
|
+
[[message, Skyward::Core::Diagnostics::Excerpt.render(spots)].compact.join("\n\n"), hint].compact.join("\n")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Only a declared name of the same kind, as `String` and not `string` for `Strng`.
|
|
76
|
+
# @rbs type_name: RBS::TypeName
|
|
77
|
+
# @rbs return: String?
|
|
78
|
+
def closest(type_name)
|
|
79
|
+
env = @builder.env
|
|
80
|
+
names = [*env.class_decls.keys, *env.class_alias_decls.keys, *env.interface_decls.keys, *env.type_alias_decls.keys]
|
|
81
|
+
declared = names.select { |name| name.kind == type_name.kind }.map { |name| written(name) }
|
|
82
|
+
Skyward::Core::Diagnostics::Suggestion.closest(written(type_name), declared)
|
|
83
|
+
end
|
|
84
|
+
|
|
47
85
|
# @rbs type: RBS::Types::t
|
|
48
86
|
# @rbs path: Array[String]
|
|
49
87
|
# @rbs return: Skyward::Core::Types::result
|
|
@@ -100,7 +138,14 @@ class Skyward::Core::Types::Reader
|
|
|
100
138
|
# @rbs path: Array[String]
|
|
101
139
|
# @rbs return: Skyward::Core::Types::result
|
|
102
140
|
def alias_type(type, path)
|
|
103
|
-
read_within(@builder.expand_alias2(type.name, type.args), enter(written(type), path))
|
|
141
|
+
expanded = read_within(@builder.expand_alias2(type.name, type.args), enter(written(type), path))
|
|
142
|
+
as = @refinements.fetch(type.name.to_s, nil)
|
|
143
|
+
return expanded unless as
|
|
144
|
+
|
|
145
|
+
case expanded
|
|
146
|
+
when Skyward::Core::Types::Unreadable then expanded
|
|
147
|
+
else Skyward::Core::Types::Refined.new(type: expanded, as:)
|
|
148
|
+
end
|
|
104
149
|
end
|
|
105
150
|
|
|
106
151
|
# @rbs type: RBS::Types::Record
|
|
@@ -146,10 +191,13 @@ class Skyward::Core::Types::Reader
|
|
|
146
191
|
# @rbs return: Skyward::Core::Types::result
|
|
147
192
|
def named(type, path)
|
|
148
193
|
readers = public_readers(type.name)
|
|
149
|
-
|
|
194
|
+
if readers.empty?
|
|
195
|
+
suggestion = closest(type.name) unless @builder.env.module_name?(type.name)
|
|
196
|
+
return unreadable(type, suggestion:)
|
|
197
|
+
end
|
|
150
198
|
|
|
151
199
|
name = written(type.name)
|
|
152
|
-
klass = ruby_class(name)
|
|
200
|
+
klass = ruby_class(type.name)
|
|
153
201
|
within = enter(name, path)
|
|
154
202
|
keys = readers.map { |reader| [reader.name, true] } #: Array[[Symbol, bool]]
|
|
155
203
|
results = readers.map { |reader| locate(read_within(reader.type, within), "#{name}##{reader.name}") }
|
|
@@ -186,13 +234,16 @@ class Skyward::Core::Types::Reader
|
|
|
186
234
|
end
|
|
187
235
|
end
|
|
188
236
|
|
|
189
|
-
# @rbs
|
|
237
|
+
# @rbs type_name: RBS::TypeName
|
|
190
238
|
# @rbs return: Class
|
|
191
|
-
def ruby_class(
|
|
239
|
+
def ruby_class(type_name)
|
|
240
|
+
name = written(type_name)
|
|
192
241
|
found = Object.const_get(name) if Object.const_defined?(name)
|
|
193
242
|
return found if found.is_a?(Class)
|
|
194
243
|
|
|
195
|
-
|
|
244
|
+
message = "#{name} has an RBS signature, but no Ruby class is loaded with that name"
|
|
245
|
+
location = @builder.env.class_entry(type_name, normalized: true)&.primary_decl&.location
|
|
246
|
+
raise Skyward::Core::BootError, explain(message, location&.[](:name))
|
|
196
247
|
end
|
|
197
248
|
|
|
198
249
|
# @rbs name: String
|
|
@@ -234,9 +285,10 @@ class Skyward::Core::Types::Reader
|
|
|
234
285
|
|
|
235
286
|
# @rbs type: RBS::Types::t
|
|
236
287
|
# @rbs instead: String
|
|
288
|
+
# @rbs suggestion: String?
|
|
237
289
|
# @rbs return: Skyward::Core::Types::Unreadable
|
|
238
|
-
def unreadable(type, instead = "a record, or a class with public typed attr_readers")
|
|
239
|
-
Skyward::Core::Types::Unreadable.new(type: written(type), at: nil, instead:)
|
|
290
|
+
def unreadable(type, instead = "a record, or a class with public typed attr_readers", suggestion: nil)
|
|
291
|
+
Skyward::Core::Types::Unreadable.new(type: written(type), at: nil, instead:, suggestion:)
|
|
240
292
|
end
|
|
241
293
|
|
|
242
294
|
# @rbs (_ToS name) -> String
|
data/lib/skyward/core/types.rb
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Skyward::Core::Types
|
|
4
4
|
# @rbs!
|
|
5
|
-
# type scalar = :integer | :float | :string | :bool | :date | :time | :untyped
|
|
5
|
+
# type scalar = :integer | :float | :string | :bool | :date | :time | :decimal | :untyped
|
|
6
6
|
# type literal = String | Integer | bool | nil
|
|
7
|
-
# type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union
|
|
7
|
+
# type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union | Refined
|
|
8
8
|
# type result = t | Unreadable
|
|
9
9
|
|
|
10
10
|
Scalar = Data.define(
|
|
@@ -51,9 +51,15 @@ module Skyward::Core::Types
|
|
|
51
51
|
:types #: Array[t]
|
|
52
52
|
)
|
|
53
53
|
|
|
54
|
+
Refined = Data.define(
|
|
55
|
+
:type, #: t
|
|
56
|
+
:as #: Symbol
|
|
57
|
+
)
|
|
58
|
+
|
|
54
59
|
Unreadable = Data.define(
|
|
55
60
|
:type, #: String
|
|
56
61
|
:at, #: String?
|
|
57
|
-
:instead #: String
|
|
62
|
+
:instead, #: String
|
|
63
|
+
:suggestion #: String?
|
|
58
64
|
)
|
|
59
65
|
end
|
data/lib/skyward/core/version.rb
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/diagnostics/excerpt.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics::Excerpt
|
|
4
|
+
INDENT: String
|
|
5
|
+
|
|
6
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
7
|
+
# @rbs directory: String
|
|
8
|
+
# @rbs return: String?
|
|
9
|
+
def render: (Array[Skyward::Core::Diagnostics::Spot] spots, ?directory: String) -> String?
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
# @rbs path: String
|
|
14
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
15
|
+
# @rbs return: String
|
|
16
|
+
def block: (String path, Array[Skyward::Core::Diagnostics::Spot] spots) -> String
|
|
17
|
+
|
|
18
|
+
# @rbs spots: Array[Skyward::Core::Diagnostics::Spot]
|
|
19
|
+
# @rbs indent: Integer
|
|
20
|
+
# @rbs return: Array[String]
|
|
21
|
+
def carets: (Array[Skyward::Core::Diagnostics::Spot] spots, Integer indent) -> Array[String]
|
|
22
|
+
|
|
23
|
+
# @rbs path: String
|
|
24
|
+
# @rbs directory: String
|
|
25
|
+
# @rbs return: String
|
|
26
|
+
def relative: (String path, String directory) -> String
|
|
27
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/diagnostics/spots.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics::Spots
|
|
4
|
+
# @rbs location: RBS::Location[untyped, untyped]
|
|
5
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot
|
|
6
|
+
def rbs: (RBS::Location[untyped, untyped] location) -> Skyward::Core::Diagnostics::Spot
|
|
7
|
+
|
|
8
|
+
# @rbs method: Method | UnboundMethod
|
|
9
|
+
# @rbs name: Symbol
|
|
10
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
11
|
+
def keyword_parameter: (Method | UnboundMethod method, Symbol name) -> Skyward::Core::Diagnostics::Spot?
|
|
12
|
+
|
|
13
|
+
# @rbs method: Method | UnboundMethod
|
|
14
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
15
|
+
def parameters: (Method | UnboundMethod method) -> Skyward::Core::Diagnostics::Spot?
|
|
16
|
+
|
|
17
|
+
# @rbs method: Method | UnboundMethod
|
|
18
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
19
|
+
def method_name: (Method | UnboundMethod method) -> Skyward::Core::Diagnostics::Spot?
|
|
20
|
+
|
|
21
|
+
# @rbs path: String
|
|
22
|
+
# @rbs line: Integer
|
|
23
|
+
# @rbs call: Symbol
|
|
24
|
+
# @rbs key: Symbol
|
|
25
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
26
|
+
def keyword_key: (String path, Integer line, call: Symbol, key: Symbol) -> Skyward::Core::Diagnostics::Spot?
|
|
27
|
+
|
|
28
|
+
# @rbs path: String
|
|
29
|
+
# @rbs line: Integer
|
|
30
|
+
# @rbs call: Symbol
|
|
31
|
+
# @rbs key: Symbol
|
|
32
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
33
|
+
def keyword_value: (String path, Integer line, call: Symbol, key: Symbol) -> Skyward::Core::Diagnostics::Spot?
|
|
34
|
+
|
|
35
|
+
# @rbs path: String
|
|
36
|
+
# @rbs line: Integer
|
|
37
|
+
# @rbs call: Symbol
|
|
38
|
+
# @rbs value: Symbol
|
|
39
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
40
|
+
def symbol: (String path, Integer line, call: Symbol, value: Symbol) -> Skyward::Core::Diagnostics::Spot?
|
|
41
|
+
|
|
42
|
+
# @rbs path: String
|
|
43
|
+
# @rbs line: Integer
|
|
44
|
+
# @rbs call: Symbol
|
|
45
|
+
# @rbs part: String
|
|
46
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
47
|
+
def string: (String path, Integer line, call: Symbol, part: String) -> Skyward::Core::Diagnostics::Spot?
|
|
48
|
+
|
|
49
|
+
# @rbs path: String
|
|
50
|
+
# @rbs line: Integer
|
|
51
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
52
|
+
def reader_type: (String path, Integer line) -> Skyward::Core::Diagnostics::Spot?
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# @rbs path: String
|
|
57
|
+
# @rbs line: Integer
|
|
58
|
+
# @rbs text: String
|
|
59
|
+
# @rbs columns: Range[Integer]
|
|
60
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot
|
|
61
|
+
def spot: (String path, Integer line, String text, Range[Integer] columns) -> Skyward::Core::Diagnostics::Spot
|
|
62
|
+
|
|
63
|
+
# @rbs path: String
|
|
64
|
+
# @rbs &: (Prism::ParseResult) -> Prism::Location?
|
|
65
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
66
|
+
def parse: (String path) { (Prism::ParseResult) -> Prism::Location? } -> Skyward::Core::Diagnostics::Spot?
|
|
67
|
+
|
|
68
|
+
# @rbs method: Method | UnboundMethod
|
|
69
|
+
# @rbs &: (Prism::DefNode) -> Prism::Location?
|
|
70
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
71
|
+
def definition: (Method | UnboundMethod method) { (Prism::DefNode) -> Prism::Location? } -> Skyward::Core::Diagnostics::Spot?
|
|
72
|
+
|
|
73
|
+
# @rbs path: String
|
|
74
|
+
# @rbs line: Integer
|
|
75
|
+
# @rbs name: Symbol
|
|
76
|
+
# @rbs &: (Array[Prism::node]) -> Prism::Location?
|
|
77
|
+
# @rbs return: Skyward::Core::Diagnostics::Spot?
|
|
78
|
+
def arguments: (String path, Integer line, Symbol name) { (Array[Prism::node]) -> Prism::Location? } -> Skyward::Core::Diagnostics::Spot?
|
|
79
|
+
|
|
80
|
+
# @rbs result: Prism::ParseResult
|
|
81
|
+
# @rbs line: Integer
|
|
82
|
+
# @rbs name: Symbol
|
|
83
|
+
# @rbs return: Prism::CallNode?
|
|
84
|
+
def call: (Prism::ParseResult result, Integer line, Symbol name) -> Prism::CallNode?
|
|
85
|
+
|
|
86
|
+
# @rbs arguments: Array[Prism::node]
|
|
87
|
+
# @rbs key: Symbol
|
|
88
|
+
# @rbs return: Prism::AssocNode?
|
|
89
|
+
def pair: (Array[Prism::node] arguments, Symbol key) -> Prism::AssocNode?
|
|
90
|
+
|
|
91
|
+
# @rbs node: Prism::node
|
|
92
|
+
# @rbs value: Symbol
|
|
93
|
+
# @rbs return: bool
|
|
94
|
+
def symbol?: (Prism::node node, Symbol value) -> bool
|
|
95
|
+
|
|
96
|
+
# Prism's locations count bytes, so a part is found by its byte offset.
|
|
97
|
+
# @rbs location: Prism::Location
|
|
98
|
+
# @rbs part: String
|
|
99
|
+
# @rbs return: Prism::Location?
|
|
100
|
+
def within: (Prism::Location location, String part) -> Prism::Location?
|
|
101
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/diagnostics/suggestion.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics::Suggestion
|
|
4
|
+
# @rbs name: String
|
|
5
|
+
# @rbs names: Array[String]
|
|
6
|
+
# @rbs return: String?
|
|
7
|
+
def closest: (String name, Array[String] names) -> String?
|
|
8
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/diagnostics.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Diagnostics
|
|
4
|
+
# The line's text travels with it, so an excerpt never reads the file again.
|
|
5
|
+
class Spot < Data
|
|
6
|
+
attr_reader path(): String
|
|
7
|
+
|
|
8
|
+
attr_reader line(): Integer
|
|
9
|
+
|
|
10
|
+
attr_reader text(): String
|
|
11
|
+
|
|
12
|
+
attr_reader columns(): Range[Integer]?
|
|
13
|
+
|
|
14
|
+
def self.new: (String path, Integer line, String text, Range[Integer]? columns) -> instance
|
|
15
|
+
| (path: String, line: Integer, text: String, columns: Range[Integer]?) -> instance
|
|
16
|
+
|
|
17
|
+
def self.members: () -> [ :path, :line, :text, :columns ]
|
|
18
|
+
|
|
19
|
+
def members: () -> [ :path, :line, :text, :columns ]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -13,4 +13,15 @@ class Skyward::Core::Signatures::Loader
|
|
|
13
13
|
# @rbs directory: String
|
|
14
14
|
# @rbs return: RBS::DefinitionBuilder
|
|
15
15
|
def load: (String directory) -> RBS::DefinitionBuilder
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
# @rbs decl: RBS::DuplicatedDeclarationError::declaration
|
|
20
|
+
# @rbs return: RBS::Location[untyped, untyped]?
|
|
21
|
+
def name_location: (RBS::DuplicatedDeclarationError::declaration decl) -> RBS::Location[untyped, untyped]?
|
|
22
|
+
|
|
23
|
+
# @rbs message: String
|
|
24
|
+
# @rbs locations: Array[RBS::Location[untyped, untyped]]
|
|
25
|
+
# @rbs return: String
|
|
26
|
+
def failure: (String message, Array[RBS::Location[untyped, untyped]] locations) -> String
|
|
16
27
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Generated from lib/skyward/core/types/reader.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
class Skyward::Core::Types::Reader
|
|
4
|
+
@refinements: Hash[String, Symbol]
|
|
5
|
+
|
|
4
6
|
@builder: RBS::DefinitionBuilder
|
|
5
7
|
|
|
6
8
|
SCALARS: Hash[String, Skyward::Core::Types::scalar]
|
|
@@ -8,8 +10,9 @@ class Skyward::Core::Types::Reader
|
|
|
8
10
|
NIL_LITERAL: Skyward::Core::Types::Literal
|
|
9
11
|
|
|
10
12
|
# @rbs builder: RBS::DefinitionBuilder
|
|
13
|
+
# @rbs refinements: Hash[String, Symbol]
|
|
11
14
|
# @rbs return: void
|
|
12
|
-
def initialize: (RBS::DefinitionBuilder builder) -> void
|
|
15
|
+
def initialize: (RBS::DefinitionBuilder builder, ?refinements: Hash[String, Symbol]) -> void
|
|
13
16
|
|
|
14
17
|
# @rbs type: RBS::Types::t
|
|
15
18
|
# @rbs return: Skyward::Core::Types::result
|
|
@@ -26,6 +29,21 @@ class Skyward::Core::Types::Reader
|
|
|
26
29
|
|
|
27
30
|
private
|
|
28
31
|
|
|
32
|
+
# @rbs error: RBS::DefinitionError
|
|
33
|
+
# @rbs return: String
|
|
34
|
+
def definition_failure: (RBS::DefinitionError error) -> String
|
|
35
|
+
|
|
36
|
+
# @rbs message: String
|
|
37
|
+
# @rbs location: RBS::Location[untyped, untyped]?
|
|
38
|
+
# @rbs suggestion: String?
|
|
39
|
+
# @rbs return: String
|
|
40
|
+
def explain: (String message, RBS::Location[untyped, untyped]? location, ?String? suggestion) -> String
|
|
41
|
+
|
|
42
|
+
# Only a declared name of the same kind, as `String` and not `string` for `Strng`.
|
|
43
|
+
# @rbs type_name: RBS::TypeName
|
|
44
|
+
# @rbs return: String?
|
|
45
|
+
def closest: (RBS::TypeName type_name) -> String?
|
|
46
|
+
|
|
29
47
|
# @rbs type: RBS::Types::t
|
|
30
48
|
# @rbs path: Array[String]
|
|
31
49
|
# @rbs return: Skyward::Core::Types::result
|
|
@@ -76,9 +94,9 @@ class Skyward::Core::Types::Reader
|
|
|
76
94
|
# @rbs return: Array[RBS::AST::Members::AttrReader]
|
|
77
95
|
def declared_public_readers: (RBS::AST::Declarations::Class decl) -> Array[RBS::AST::Members::AttrReader]
|
|
78
96
|
|
|
79
|
-
# @rbs
|
|
97
|
+
# @rbs type_name: RBS::TypeName
|
|
80
98
|
# @rbs return: Class
|
|
81
|
-
def ruby_class: (
|
|
99
|
+
def ruby_class: (RBS::TypeName type_name) -> Class
|
|
82
100
|
|
|
83
101
|
# @rbs name: String
|
|
84
102
|
# @rbs path: Array[String]
|
|
@@ -102,8 +120,9 @@ class Skyward::Core::Types::Reader
|
|
|
102
120
|
|
|
103
121
|
# @rbs type: RBS::Types::t
|
|
104
122
|
# @rbs instead: String
|
|
123
|
+
# @rbs suggestion: String?
|
|
105
124
|
# @rbs return: Skyward::Core::Types::Unreadable
|
|
106
|
-
def unreadable: (RBS::Types::t type, ?String instead) -> Skyward::Core::Types::Unreadable
|
|
125
|
+
def unreadable: (RBS::Types::t type, ?String instead, ?suggestion: String?) -> Skyward::Core::Types::Unreadable
|
|
107
126
|
|
|
108
127
|
# @rbs (_ToS name) -> String
|
|
109
128
|
def written: (_ToS name) -> String
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Generated from lib/skyward/core/types.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Skyward::Core::Types
|
|
4
|
-
type scalar = :integer | :float | :string | :bool | :date | :time | :untyped
|
|
4
|
+
type scalar = :integer | :float | :string | :bool | :date | :time | :decimal | :untyped
|
|
5
5
|
|
|
6
6
|
type literal = String | Integer | bool | nil
|
|
7
7
|
|
|
8
|
-
type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union
|
|
8
|
+
type t = Scalar | Literal | Enum | Nullable | ArrayOf | HashOf | Record | Named | Union | Refined
|
|
9
9
|
|
|
10
10
|
type result = t | Unreadable
|
|
11
11
|
|
|
@@ -127,6 +127,19 @@ module Skyward::Core::Types
|
|
|
127
127
|
def members: () -> [ :types ]
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
+
class Refined < Data
|
|
131
|
+
attr_reader type(): t
|
|
132
|
+
|
|
133
|
+
attr_reader as(): Symbol
|
|
134
|
+
|
|
135
|
+
def self.new: (t type, Symbol as) -> instance
|
|
136
|
+
| (type: t, as: Symbol) -> instance
|
|
137
|
+
|
|
138
|
+
def self.members: () -> [ :type, :as ]
|
|
139
|
+
|
|
140
|
+
def members: () -> [ :type, :as ]
|
|
141
|
+
end
|
|
142
|
+
|
|
130
143
|
class Unreadable < Data
|
|
131
144
|
attr_reader type(): String
|
|
132
145
|
|
|
@@ -134,11 +147,13 @@ module Skyward::Core::Types
|
|
|
134
147
|
|
|
135
148
|
attr_reader instead(): String
|
|
136
149
|
|
|
137
|
-
|
|
138
|
-
|
|
150
|
+
attr_reader suggestion(): String?
|
|
151
|
+
|
|
152
|
+
def self.new: (String type, String? at, String instead, String? suggestion) -> instance
|
|
153
|
+
| (type: String, at: String?, instead: String, suggestion: String?) -> instance
|
|
139
154
|
|
|
140
|
-
def self.members: () -> [ :type, :at, :instead ]
|
|
155
|
+
def self.members: () -> [ :type, :at, :instead, :suggestion ]
|
|
141
156
|
|
|
142
|
-
def members: () -> [ :type, :at, :instead ]
|
|
157
|
+
def members: () -> [ :type, :at, :instead, :suggestion ]
|
|
143
158
|
end
|
|
144
159
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: skyward-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jake Bottrall
|
|
@@ -9,6 +9,20 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: prism
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.6'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.6'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: rbs
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -51,6 +65,10 @@ files:
|
|
|
51
65
|
- lib/skyward/core/cli.rb
|
|
52
66
|
- lib/skyward/core/cli/executable.rb
|
|
53
67
|
- lib/skyward/core/cli/registry.rb
|
|
68
|
+
- lib/skyward/core/diagnostics.rb
|
|
69
|
+
- lib/skyward/core/diagnostics/excerpt.rb
|
|
70
|
+
- lib/skyward/core/diagnostics/spots.rb
|
|
71
|
+
- lib/skyward/core/diagnostics/suggestion.rb
|
|
54
72
|
- lib/skyward/core/signatures.rb
|
|
55
73
|
- lib/skyward/core/signatures/inline.rb
|
|
56
74
|
- lib/skyward/core/signatures/loader.rb
|
|
@@ -62,6 +80,10 @@ files:
|
|
|
62
80
|
- sig/generated/skyward/core/cli.rbs
|
|
63
81
|
- sig/generated/skyward/core/cli/executable.rbs
|
|
64
82
|
- sig/generated/skyward/core/cli/registry.rbs
|
|
83
|
+
- sig/generated/skyward/core/diagnostics.rbs
|
|
84
|
+
- sig/generated/skyward/core/diagnostics/excerpt.rbs
|
|
85
|
+
- sig/generated/skyward/core/diagnostics/spots.rbs
|
|
86
|
+
- sig/generated/skyward/core/diagnostics/suggestion.rbs
|
|
65
87
|
- sig/generated/skyward/core/signatures.rbs
|
|
66
88
|
- sig/generated/skyward/core/signatures/inline.rbs
|
|
67
89
|
- sig/generated/skyward/core/signatures/loader.rbs
|
|
@@ -70,6 +92,9 @@ files:
|
|
|
70
92
|
- sig/generated/skyward/core/version.rbs
|
|
71
93
|
- sig/manual/skyward/core/cli.rbs
|
|
72
94
|
- sig/manual/skyward/core/cli/executable.rbs
|
|
95
|
+
- sig/manual/skyward/core/diagnostics/excerpt.rbs
|
|
96
|
+
- sig/manual/skyward/core/diagnostics/spots.rbs
|
|
97
|
+
- sig/manual/skyward/core/diagnostics/suggestion.rbs
|
|
73
98
|
- sig/manual/skyward/core/signatures.rbs
|
|
74
99
|
- sig/manual/skyward/core/signatures/inline.rbs
|
|
75
100
|
homepage: https://github.com/bottrall/skyward
|