Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

feat: update regex to only apply to symbols #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.activate = function(context) {
const document = editor.document;

if (editor && document.languageId === "ruby" || document.languageId === "haml" || document.languageId === "erb") {
const pattern = /:?(["|']?(\w[^\w\s]?)+["|']?)+\s*?=>\s*/g
const pattern = /[\d|:((\w[^\w\s]?))]+\s*?=>\s*/g
Copy link

@patbl patbl Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I paste it into a JavaScript console, I get a syntax error:

/[\d|:((\w[^\w\s]?))]+\s*?=>\s*/g
VM270:1 Uncaught SyntaxError: Invalid regular expression: /[\d|:((\w[^\w\s]?))]+\s*?=>\s*/: Unmatched ')'
    at <anonymous>:1:1

Also, the Ruby code in your example here is syntactically invalid, since you can't use numbers as keys in Ruby hashes with the colon syntax:

[1] pry(main)> { 1: :lol }
SyntaxError: unexpected ':', expecting =>
{ 1: :lol }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit I've not used Ruby for almost two years now, but the syntax I'm using in my examples all worked fine when I was testing, which is why I'm confused by all of this.

I'll gladly accept contributions if you have a better solution in mind.

const replacement = "$1: ";

let edit = new WorkspaceEdit();
Expand Down