Refactor the injection marker type #12561
Open
+40
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a rewrite of the
LanguageInjectionMarker
type with two purposes:LanguageId
variant that can be used to look up languages bylanguage_id
. This is used instead ofName
for(#set! injection.language "lang")
.Name
,Filename
andShebang
variants can all useRopeSlice
as their inner type and avoid allocations in the common case.The first change should be the more impactful one:
(#set! injection.language "language-id")
is far more common than capturing@injection.language
, which is used for things like markdown code fences. Previously we treated both as theName
variant meaning that we looked the languages up by the longest matchinginjection_regex
. Instead we can lookup by checking equality with thelanguage_id
field which is much cheaper. There's really no need to be flexible in what we accept for the(#set! injection.language ..)
version. For me locally this change noticeably reduces editing lag on a large Markdown file like theCHANGELOG.md
.