syntax_suggest 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/check_changelog.yml +1 -1
- data/.github/workflows/ci.yml +3 -3
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +10 -10
- data/lib/syntax_suggest/capture_code_context.rb +2 -2
- data/lib/syntax_suggest/cli.rb +2 -2
- data/lib/syntax_suggest/core_ext.rb +45 -38
- data/lib/syntax_suggest/display_code_with_line_numbers.rb +3 -3
- data/lib/syntax_suggest/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3c694e7b419ea1a715d2cccf55e706be86035c2563e2f4506769da76829a65a
|
4
|
+
data.tar.gz: a42f42ceb34fc29e0534072cc25e27e7b416c7a954ec6ccdc75c5748db491e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 755b4e3e2a5bb86ae61b4f29417a0a4f6531dbe5866ce32d56e0cb2452496fb858469bbeb3aa369ca953814e475cb52e93c2273eb54ec203cff98520d10bac07
|
7
|
+
data.tar.gz: 178a7ecd8a04d8f53f1778a331400273a2980f42451942012c3e98d5171ab30c590e76eaf69b6c78d7c63274f8040cce2e4e4f85ad35601c34fe46149420aa44
|
@@ -13,7 +13,7 @@ jobs:
|
|
13
13
|
!contains(github.event.pull_request.body, '[skip ci]') &&
|
14
14
|
!contains(github.event.pull_request.labels.*.name, 'skip changelog')
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v3.2.0
|
17
17
|
- name: Check that CHANGELOG is touched
|
18
18
|
run: |
|
19
19
|
git fetch origin ${{ github.base_ref }} --depth 1 && \
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,7 +9,7 @@ jobs:
|
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
steps:
|
11
11
|
- name: Checkout code
|
12
|
-
uses: actions/checkout@v3
|
12
|
+
uses: actions/checkout@v3.2.0
|
13
13
|
- name: Set up Ruby
|
14
14
|
uses: ruby/setup-ruby@v1
|
15
15
|
with:
|
@@ -29,11 +29,11 @@ jobs:
|
|
29
29
|
- 2.7
|
30
30
|
- '3.0'
|
31
31
|
- 3.1
|
32
|
-
- "3.2.0-
|
32
|
+
- "3.2.0-rc1"
|
33
33
|
- head
|
34
34
|
steps:
|
35
35
|
- name: Checkout code
|
36
|
-
uses: actions/checkout@v3
|
36
|
+
uses: actions/checkout@v3.2.0
|
37
37
|
- name: Set up Ruby
|
38
38
|
uses: ruby/setup-ruby@v1
|
39
39
|
with:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## HEAD (unreleased)
|
2
2
|
|
3
|
+
## 1.0.2
|
4
|
+
|
5
|
+
- Drop support or Ruby 3.2.0 preview, now that 3.2.0-rc1 is available (https://github.com/ruby/syntax_suggest/pull/165)
|
6
|
+
- Native support of `SyntaxError#path`, support 3.2.0-preview3 will be dropped with the release of 3.2.0-preview4 (https://github.com/ruby/syntax_suggest/pull/164)
|
7
|
+
- Added dependabot for GitHub Actions (https://github.com/ruby/syntax_suggest/pull/160)
|
8
|
+
|
9
|
+
## 1.0.1
|
10
|
+
|
11
|
+
- Replace `❯` with `>` in error output for compatability with more fonts (https://github.com/ruby/syntax_suggest/pull/161)
|
12
|
+
|
3
13
|
## 1.0.0 (Library renamed to syntax_suggest )
|
4
14
|
|
5
15
|
- [Breaking] Output "Syntax OK" will no longer be output when `syntax_suggest` is fired due to a syntax error. (https://github.com/ruby/syntax_suggest/pull/158)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,8 +6,8 @@ An error in your code forces you to stop. SyntaxSuggest helps you find those err
|
|
6
6
|
Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
|
7
7
|
|
8
8
|
1 class Dog
|
9
|
-
|
10
|
-
|
9
|
+
> 2 defbark
|
10
|
+
> 4 end
|
11
11
|
5 end
|
12
12
|
```
|
13
13
|
|
@@ -72,9 +72,9 @@ end
|
|
72
72
|
```
|
73
73
|
Unmatched keyword, missing `end' ?
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
> 1 class Dog
|
76
|
+
> 2 def bark
|
77
|
+
> 4 end
|
78
78
|
```
|
79
79
|
|
80
80
|
- Missing keyword
|
@@ -95,8 +95,8 @@ Unmatched `end', missing keyword (`do', `def`, `if`, etc.) ?
|
|
95
95
|
|
96
96
|
1 class Dog
|
97
97
|
2 def speak
|
98
|
-
|
99
|
-
|
98
|
+
> 3 @sounds.each |sound|
|
99
|
+
> 5 end
|
100
100
|
6 end
|
101
101
|
7 end
|
102
102
|
```
|
@@ -117,8 +117,8 @@ end
|
|
117
117
|
Unmatched `(', missing `)' ?
|
118
118
|
|
119
119
|
1 class Dog
|
120
|
-
|
121
|
-
|
120
|
+
> 2 def speak(sound
|
121
|
+
> 4 end
|
122
122
|
5 end
|
123
123
|
```
|
124
124
|
|
@@ -137,7 +137,7 @@ syntax error, unexpected end-of-input
|
|
137
137
|
|
138
138
|
1 class Dog
|
139
139
|
2 def meals_last_month
|
140
|
-
|
140
|
+
> 3 puts 3 *
|
141
141
|
4 end
|
142
142
|
5 end
|
143
143
|
```
|
@@ -140,7 +140,7 @@ module SyntaxSuggest
|
|
140
140
|
# However due to https://github.com/ruby/syntax_suggest/issues/32
|
141
141
|
# the problem line will be identified as:
|
142
142
|
#
|
143
|
-
#
|
143
|
+
# > class Dog # 1
|
144
144
|
#
|
145
145
|
# Because lines 2, 3, and 4 are technically valid code and are expanded
|
146
146
|
# first, deemed valid, and hidden. We need to un-hide the matching end
|
@@ -200,7 +200,7 @@ module SyntaxSuggest
|
|
200
200
|
#
|
201
201
|
# the problem line will be identified as:
|
202
202
|
#
|
203
|
-
#
|
203
|
+
# > end # 4
|
204
204
|
#
|
205
205
|
# This happens because lines 1, 2, and 3 are technically valid code and are expanded
|
206
206
|
# first, deemed valid, and hidden. We need to un-hide the matching keyword on
|
data/lib/syntax_suggest/cli.rb
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
# Ruby 3.2+ has a cleaner way to hook into Ruby that doesn't use `require`
|
4
4
|
if SyntaxError.method_defined?(:detailed_message)
|
5
5
|
module SyntaxSuggest
|
6
|
+
# Mini String IO [Private]
|
7
|
+
#
|
8
|
+
# Acts like a StringIO with reduced API, but without having to require that
|
9
|
+
# class.
|
6
10
|
class MiniStringIO
|
7
11
|
def initialize(isatty: $stderr.isatty)
|
8
12
|
@string = +""
|
@@ -16,46 +20,49 @@ if SyntaxError.method_defined?(:detailed_message)
|
|
16
20
|
|
17
21
|
attr_reader :string
|
18
22
|
end
|
19
|
-
end
|
20
|
-
|
21
|
-
SyntaxError.prepend Module.new {
|
22
|
-
def detailed_message(highlight: true, syntax_suggest: true, **kwargs)
|
23
|
-
return super unless syntax_suggest
|
24
|
-
|
25
|
-
require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE)
|
26
|
-
|
27
|
-
message = super
|
28
|
-
file = if highlight
|
29
|
-
SyntaxSuggest::PathnameFromMessage.new(super(highlight: false, **kwargs)).call.name
|
30
|
-
else
|
31
|
-
SyntaxSuggest::PathnameFromMessage.new(message).call.name
|
32
|
-
end
|
33
|
-
|
34
|
-
io = SyntaxSuggest::MiniStringIO.new
|
35
23
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
24
|
+
# SyntaxSuggest.record_dir [Private]
|
25
|
+
#
|
26
|
+
# Used to monkeypatch SyntaxError via Module.prepend
|
27
|
+
def self.module_for_detailed_message
|
28
|
+
Module.new {
|
29
|
+
def detailed_message(highlight: true, syntax_suggest: true, **kwargs)
|
30
|
+
return super unless syntax_suggest
|
31
|
+
|
32
|
+
require "syntax_suggest/api" unless defined?(SyntaxSuggest::DEFAULT_VALUE)
|
33
|
+
|
34
|
+
message = super
|
35
|
+
|
36
|
+
if path
|
37
|
+
file = Pathname.new(path)
|
38
|
+
io = SyntaxSuggest::MiniStringIO.new
|
39
|
+
|
40
|
+
SyntaxSuggest.call(
|
41
|
+
io: io,
|
42
|
+
source: file.read,
|
43
|
+
filename: file,
|
44
|
+
terminal: highlight
|
45
|
+
)
|
46
|
+
annotation = io.string
|
47
|
+
|
48
|
+
annotation + message
|
49
|
+
else
|
50
|
+
message
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
if ENV["SYNTAX_SUGGEST_DEBUG"]
|
54
|
+
$stderr.warn(e.message)
|
55
|
+
$stderr.warn(e.backtrace)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Ignore internal errors
|
59
|
+
message
|
60
|
+
end
|
61
|
+
}
|
57
62
|
end
|
58
|
-
|
63
|
+
end
|
64
|
+
|
65
|
+
SyntaxError.prepend(SyntaxSuggest.module_for_detailed_message)
|
59
66
|
else
|
60
67
|
autoload :Pathname, "pathname"
|
61
68
|
|
@@ -14,8 +14,8 @@ module SyntaxSuggest
|
|
14
14
|
# # =>
|
15
15
|
# 1
|
16
16
|
# 2 def cat
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# > 3 Dir.chdir
|
18
|
+
# > 4 end
|
19
19
|
# 5 end
|
20
20
|
# 6
|
21
21
|
class DisplayCodeWithLineNumbers
|
@@ -50,7 +50,7 @@ module SyntaxSuggest
|
|
50
50
|
private def format(contents:, number:, empty:, highlight: false)
|
51
51
|
string = +""
|
52
52
|
string << if highlight
|
53
|
-
"
|
53
|
+
"> "
|
54
54
|
else
|
55
55
|
" "
|
56
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_suggest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- schneems
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: When you get an "unexpected end" in your syntax this gem helps you find
|
14
14
|
it
|
@@ -19,6 +19,7 @@ executables:
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- ".github/dependabot.yml"
|
22
23
|
- ".github/workflows/check_changelog.yml"
|
23
24
|
- ".github/workflows/ci.yml"
|
24
25
|
- ".gitignore"
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.4.0.dev
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Find syntax errors in your source in a snap
|