skyward-core 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d15866bdd2c7b1d8f40d7df67376f058506ae1e691cc0b03fca8b772ac446ed1
4
- data.tar.gz: f0290b3ac8aa9a8f28bba4a4efe1f4aeea869df2c646a127bd79091acd916f6e
3
+ metadata.gz: e3fd98462e9c708fda03399e73fd8ecfdd78377ac8e627c1b932b91a6f8a28d7
4
+ data.tar.gz: 3eefa7cd5299ef5ab7eec622619ea731fa5684e97bdf8c4d9b15ac757a5951fb
5
5
  SHA512:
6
- metadata.gz: 491bcff7ee20393ef3749ef042577af5a0890d64e3b99de178104ce233f1c568abba00ae0fe5b7114047665c8c91bbbb3f73ee1df2b8a8c5dd620bbc164e49c4
7
- data.tar.gz: 6b188b20087261bf4b63b4a978848b906e16303b979ca3daa5f3b9c4d5de77465fcf7339fb9bd111eac0e7f1bbdf5cb1861d5e546023fee9cea8e55603577a0f
6
+ metadata.gz: 1df469b179dbedd31e0736b436f5aeaebcc560e662a43ba46a8424e69b6bdd759a00c84801bd0ccb22b2d85ae1a561c0d9df5568c50466e6e1e562a01ef86d9b
7
+ data.tar.gz: bf50ced3df262eb2b0d45a93592e5147d32ea0862cfe392b9ba9d50f1b7bb8e152e9ea8d161df68ea85b7a30004b398ea807b80312e6196689782a20fd70fd09
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Skyward Core
2
2
 
3
3
  > [!CAUTION]
4
- > **Work in progress: Skyward Core is barely started.** Version 0.1 is a skeleton. The gems install and load, and only the parts [Status](#status) lists are built. This README is the spec for what's coming, not documentation of what exists. Don't depend on it yet.
4
+ > Skyward is pre-1.0. Everything this README describes is built, as [Status](#status) lists, but parts of the [Skyward API](../skyward-api/README.md#status) and [Skyward ORM](../skyward-orm/README.md#status) specs aren't yet. Any release may change the API, so don't run it in production yet.
5
5
 
6
6
  The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../skyward-orm/README.md) share. You don't add it to your Gemfile: each of them depends on it, at exactly the same version.
7
7
 
@@ -10,8 +10,10 @@ The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../s
10
10
  - **The `Skyward` namespace.** Skyward Core opens it, and every Skyward gem's Zeitwerk loader extends it. Each gem's names live in that gem's own namespace there: `Skyward::Core`, `Skyward::API` and `Skyward::ORM`.
11
11
  - **The `skyward` command.** It comes with Skyward Core, so it's there whichever Skyward gems you install. Each gem adds its own commands to it.
12
12
  - **Loading RBS signatures.** One loader finds your app's signatures and those of the gems it uses, for every Skyward gem.
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.
13
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.
14
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.
15
17
 
16
18
  ## Adding commands
17
19
 
@@ -31,9 +33,11 @@ Skyward supports every Ruby that isn't end-of-life (3.3 and later, as of Novembe
31
33
 
32
34
  ## Status
33
35
 
34
- This README is the spec. Skyward 0.1 is a skeleton: the gem installs, opens the `Skyward` namespace and sets up its loader. This section lists each part as it lands.
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.
35
37
 
36
- - **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.
37
- - **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 `time` 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` naming the file and line.
38
- - **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 `Union`. 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. 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`) and what to use instead, for the caller to raise `Skyward::Core::BootError` with its own context. A class with no loaded Ruby class, or a type that refers to itself, raises `Skyward::Core::BootError`. `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.
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.
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.
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.
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.
39
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,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skyward::Core::CLI::Executable
4
+ extend self
5
+
6
+ # @rbs! type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [String, bool]
7
+
8
+ CAPTURE = lambda do |env, command, chdir|
9
+ # RBS doesn't list the [:child, :out] spelling of this redirect.
10
+ output = IO.popen(env, command, chdir:, err: [:child, 1], &:read)
11
+ # RBS doesn't declare Process.last_status, set by the popen above.
12
+ [output, Process.last_status.success?] # steep:ignore NoMethod
13
+ end #: capture
14
+
15
+ # Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
16
+ # so a gem installed outside the app's bundle isn't found. Checking first
17
+ # spares rescuing the error bin_path raises for a missing gem.
18
+ # @rbs name: String
19
+ # @rbs feature: String
20
+ # @rbs return: String?
21
+ def find(name, feature: name)
22
+ Gem.bin_path(name, name) unless Gem.find_files("#{feature}.rb").empty?
23
+ end
24
+ end
@@ -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
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "tmpdir"
5
+
6
+ module Skyward::Core::Signatures::Inline
7
+ extend self
8
+
9
+ OUTPUT = "sig/generated" #: String
10
+
11
+ # None holds the app's contract: its tests, its installed gems and scratch.
12
+ UNCHECKED = %w[test spec vendor tmp].freeze #: Array[String]
13
+
14
+ # rbs-inline writes to scratch, so a file it no longer generates can be
15
+ # removed, and only a file whose content changed is written: skyward serve
16
+ # reloads on every .rbs file written.
17
+ # @rbs directory: String
18
+ # @rbs rbs_inline: String?
19
+ # @rbs capture: Skyward::Core::CLI::Executable::capture
20
+ # @rbs return: String?
21
+ def generate(directory, rbs_inline:, capture:)
22
+ return unless rbs_inline
23
+
24
+ files = run(directory, rbs_inline:, capture:)
25
+ case files
26
+ when String then "rbs-inline couldn't regenerate #{OUTPUT}:\n#{files}"
27
+ else
28
+ write(File.join(directory, OUTPUT), files)
29
+ nil
30
+ end
31
+ end
32
+
33
+ # @rbs directory: String
34
+ # @rbs rbs_inline: String
35
+ # @rbs capture: Skyward::Core::CLI::Executable::capture
36
+ # @rbs return: Hash[String, String] | String
37
+ def run(directory, rbs_inline:, capture:)
38
+ Dir.mktmpdir("skyward-signatures") do |output|
39
+ log, ok = capture.call({}, [Gem.ruby, rbs_inline, "--output=#{output}", *sources(directory)], directory)
40
+ ok ? rbs_files(output) : log
41
+ end
42
+ end
43
+
44
+ # @rbs directory: String
45
+ # @rbs return: Array[String]
46
+ def sources(directory)
47
+ roots = Dir.glob("*/", base: directory).map { |root| root.delete_suffix("/") } - UNCHECKED
48
+ files = Dir.glob("*.rb", base: directory)
49
+ [*files, *roots.reject { |root| Dir.glob("#{root}/**/*.rb", base: directory).empty? }].sort
50
+ end
51
+
52
+ # @rbs directory: String
53
+ # @rbs return: Hash[String, String]
54
+ def rbs_files(directory)
55
+ Dir.glob("**/*.rbs", base: directory).to_h { |file| [file, File.read(File.join(directory, file))] }
56
+ end
57
+
58
+ private
59
+
60
+ # @rbs generated: String
61
+ # @rbs files: Hash[String, String]
62
+ # @rbs return: void
63
+ def write(generated, files)
64
+ current = rbs_files(generated)
65
+ files.reject { |file, source| current[file] == source }.each do |file, source|
66
+ path = File.join(generated, file)
67
+ FileUtils.mkdir_p(File.dirname(path))
68
+ File.write(path, source)
69
+ end
70
+ (current.keys - files.keys).each { |file| File.delete(File.join(generated, file)) }
71
+ # Deepest first, so a directory emptied of directories goes too.
72
+ Dir.glob("**/*/", base: generated).sort.reverse_each do |dir|
73
+ path = File.join(generated, dir)
74
+ Dir.rmdir(path) if Dir.empty?(path)
75
+ end
76
+ end
77
+ 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
- locations = e.decls.map { |decl| RBS::Location.to_string(decl.location) }
31
- raise Skyward::Core::BootError, "Can't load the RBS signatures: #{e.name} is declared at #{locations.join(" and ")}"
32
- rescue RBS::ParsingError, RBS::GenericParameterMismatchError => e
33
- raise Skyward::Core::BootError, "Can't load the RBS signatures: #{e.message}"
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, "Can't read the RBS signatures: #{e.message}"
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
- return unreadable(type) if readers.empty?
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 name: String
237
+ # @rbs type_name: RBS::TypeName
190
238
  # @rbs return: Class
191
- def ruby_class(name)
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
- raise Skyward::Core::BootError, "#{name} has an RBS signature, but no Ruby class is loaded with that name"
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
@@ -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
@@ -4,7 +4,7 @@ module Skyward
4
4
  module Core
5
5
  # x-release-please-start-version
6
6
 
7
- VERSION = "0.2.0" #: String
7
+ VERSION = "0.4.0" #: String
8
8
 
9
9
  # x-release-please-end
10
10
  end
@@ -0,0 +1,15 @@
1
+ # Generated from lib/skyward/core/cli/executable.rb with RBS::Inline
2
+
3
+ module Skyward::Core::CLI::Executable
4
+ type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [ String, bool ]
5
+
6
+ CAPTURE: capture
7
+
8
+ # Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
9
+ # so a gem installed outside the app's bundle isn't found. Checking first
10
+ # spares rescuing the error bin_path raises for a missing gem.
11
+ # @rbs name: String
12
+ # @rbs feature: String
13
+ # @rbs return: String?
14
+ def find: (String name, ?feature: String) -> String?
15
+ end
@@ -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
@@ -0,0 +1,38 @@
1
+ # Generated from lib/skyward/core/signatures/inline.rb with RBS::Inline
2
+
3
+ module Skyward::Core::Signatures::Inline
4
+ OUTPUT: String
5
+
6
+ # None holds the app's contract: its tests, its installed gems and scratch.
7
+ UNCHECKED: Array[String]
8
+
9
+ # rbs-inline writes to scratch, so a file it no longer generates can be
10
+ # removed, and only a file whose content changed is written: skyward serve
11
+ # reloads on every .rbs file written.
12
+ # @rbs directory: String
13
+ # @rbs rbs_inline: String?
14
+ # @rbs capture: Skyward::Core::CLI::Executable::capture
15
+ # @rbs return: String?
16
+ def generate: (String directory, rbs_inline: String?, capture: Skyward::Core::CLI::Executable::capture) -> String?
17
+
18
+ # @rbs directory: String
19
+ # @rbs rbs_inline: String
20
+ # @rbs capture: Skyward::Core::CLI::Executable::capture
21
+ # @rbs return: Hash[String, String] | String
22
+ def run: (String directory, rbs_inline: String, capture: Skyward::Core::CLI::Executable::capture) -> (Hash[String, String] | String)
23
+
24
+ # @rbs directory: String
25
+ # @rbs return: Array[String]
26
+ def sources: (String directory) -> Array[String]
27
+
28
+ # @rbs directory: String
29
+ # @rbs return: Hash[String, String]
30
+ def rbs_files: (String directory) -> Hash[String, String]
31
+
32
+ private
33
+
34
+ # @rbs generated: String
35
+ # @rbs files: Hash[String, String]
36
+ # @rbs return: void
37
+ def write: (String generated, Hash[String, String] files) -> void
38
+ 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 name: String
97
+ # @rbs type_name: RBS::TypeName
80
98
  # @rbs return: Class
81
- def ruby_class: (String name) -> 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
- def self.new: (String type, String? at, String instead) -> instance
138
- | (type: String, at: String?, instead: String) -> instance
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
@@ -0,0 +1,3 @@
1
+ module Skyward::Core::CLI::Executable
2
+ extend ::Skyward::Core::CLI::Executable
3
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Core::Diagnostics::Excerpt
2
+ extend ::Skyward::Core::Diagnostics::Excerpt
3
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Core::Diagnostics::Spots
2
+ extend ::Skyward::Core::Diagnostics::Spots
3
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Core::Diagnostics::Suggestion
2
+ extend ::Skyward::Core::Diagnostics::Suggestion
3
+ end
@@ -0,0 +1,3 @@
1
+ module Skyward::Core::Signatures::Inline
2
+ extend ::Skyward::Core::Signatures::Inline
3
+ 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.2.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
@@ -49,8 +63,14 @@ files:
49
63
  - lib/skyward/core.rb
50
64
  - lib/skyward/core/boot_error.rb
51
65
  - lib/skyward/core/cli.rb
66
+ - lib/skyward/core/cli/executable.rb
52
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
53
72
  - lib/skyward/core/signatures.rb
73
+ - lib/skyward/core/signatures/inline.rb
54
74
  - lib/skyward/core/signatures/loader.rb
55
75
  - lib/skyward/core/types.rb
56
76
  - lib/skyward/core/types/reader.rb
@@ -58,14 +78,25 @@ files:
58
78
  - sig/generated/skyward/core.rbs
59
79
  - sig/generated/skyward/core/boot_error.rbs
60
80
  - sig/generated/skyward/core/cli.rbs
81
+ - sig/generated/skyward/core/cli/executable.rbs
61
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
62
87
  - sig/generated/skyward/core/signatures.rbs
88
+ - sig/generated/skyward/core/signatures/inline.rbs
63
89
  - sig/generated/skyward/core/signatures/loader.rbs
64
90
  - sig/generated/skyward/core/types.rbs
65
91
  - sig/generated/skyward/core/types/reader.rbs
66
92
  - sig/generated/skyward/core/version.rbs
67
93
  - sig/manual/skyward/core/cli.rbs
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
68
98
  - sig/manual/skyward/core/signatures.rbs
99
+ - sig/manual/skyward/core/signatures/inline.rbs
69
100
  homepage: https://github.com/bottrall/skyward
70
101
  licenses:
71
102
  - MIT