Skip to content

Commit d7f699c

Browse files
committed
Update React and Solid version
1 parent addf57d commit d7f699c

File tree

4 files changed

+74
-62
lines changed

4 files changed

+74
-62
lines changed

react-package/src/extensions/autocomplete/javascript/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { PrismEditor } from "../../../index.js"
44
import { braces, space } from "../../../languages/shared/index.js"
5+
import { TokenName } from "../../../prism/index.js"
56
import { getClosestToken } from "../../../utils/index.js"
67
import { Bracket } from "../../match-brackets"
78
import { Completion, CompletionContext, CompletionSource } from "../types.js"
@@ -206,9 +207,11 @@ const includedTypes = new Set([
206207
"property-access",
207208
"maybe-class-name",
208209
"generic-function",
210+
"expression",
209211
])
210212

211-
const identifierFilter = (type: string) => includedTypes.has(type)
213+
const identifierFilter = (value: string) => (type: TokenName, start: number) =>
214+
includedTypes.has(type) || (type == "tag" && value[start] == "<")
212215

213216
const identifierSearch = RegExp(`${identifierPattern}+`, "g")
214217

@@ -224,7 +227,13 @@ const completeIdentifiers = (identifiers?: Iterable<string>): CompletionSource<J
224227
? {
225228
from: getFrom(context),
226229
options: Array.from(
227-
findWords(context, editor, identifierFilter, identifierSearch, identifiers),
230+
findWords(
231+
context,
232+
editor,
233+
identifierFilter(editor.value),
234+
identifierSearch,
235+
identifiers,
236+
),
228237
label => ({
229238
label,
230239
icon: "text",
@@ -259,7 +268,13 @@ const jsCompletion = (scope: any, identifiers?: Iterable<string>): CompletionSou
259268
labels = scopeResult[1]
260269
} else completions = []
261270

262-
findWords(context, editor, identifierFilter, identifierSearch, identifiers).forEach(word => {
271+
findWords(
272+
context,
273+
editor,
274+
identifierFilter(editor.value),
275+
identifierSearch,
276+
identifiers,
277+
).forEach(word => {
263278
if (!labels?.has(word))
264279
completions.push({
265280
label: word,

react-package/src/extensions/autocomplete/utils.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PrismEditor } from "../.."
2-
import { Token, TokenStream } from "../../prism"
2+
import { Token, TokenName, TokenStream } from "../../prism"
33
import { updateNode } from "../../utils/local"
44
import { matchTemplate } from "../search/search"
55
import { map } from "./tooltip"
@@ -53,7 +53,7 @@ const completeFromList = (options: Completion[]): CompletionSource<{ path: strin
5353
* @param filter Function used to filter tokens you want to search in. Is called with the
5454
* type of the token and its starting position. If the filter returns true, the token
5555
* will be searched.
56-
* @param pattern Pattern used to search for words.
56+
* @param pattern Pattern used to search for words. Must have the `g` flag.
5757
* @param init Words that should be completed even if they're not found in the document.
5858
* @param tokensOnly If `true` only the text of tokens whose `content` is a string will
5959
* be searched. If `false`, any string inside the {@link TokenStream} can be searched.
@@ -62,7 +62,7 @@ const completeFromList = (options: Completion[]): CompletionSource<{ path: strin
6262
const findWords = (
6363
context: CompletionContext,
6464
editor: PrismEditor,
65-
filter: (type: string, start: number) => boolean,
65+
filter: (type: TokenName, start: number) => boolean,
6666
pattern: RegExp,
6767
init?: Iterable<string>,
6868
tokensOnly?: boolean,
@@ -73,37 +73,28 @@ const findWords = (
7373
const search = (tokens: TokenStream, pos: number, isCorrectLang: boolean) => {
7474
let i = 0
7575
let token: string | Token
76-
if (isCorrectLang) {
77-
for (; (token = tokens[i++]); ) {
78-
if (typeof token == "string") {
79-
if (!tokensOnly) match(token, pos)
80-
} else {
81-
const type = token.type
82-
const content = token.content
83-
if ((token.alias || type).slice(0, 9) != "language-" && filter(type, pos)) {
84-
if (Array.isArray(content)) {
85-
search(content, pos, true)
86-
} else match(content, pos)
87-
}
88-
}
89-
pos += token.length
90-
}
91-
} else {
92-
for (; (token = tokens[i++]); ) {
93-
if (typeof token != "string") {
94-
const type = token.type
95-
const content = token.content
96-
if (Array.isArray(content)) {
97-
const aliasType = token.alias || type
76+
77+
for (; (token = tokens[i++]); ) {
78+
if (typeof token == "string") {
79+
if (!tokensOnly && isCorrectLang) match(token, pos)
80+
} else {
81+
const type = token.type
82+
const content = token.content
83+
const aliasType = token.alias || type
84+
85+
if (Array.isArray(content)) {
86+
if (!isCorrectLang || filter(type, pos)) {
9887
search(
9988
content,
10089
pos,
101-
aliasType.slice(0, 9) == "language-" ? definition == map[aliasType.slice(9)] : false,
90+
aliasType.slice(0, 9) == "language-"
91+
? definition == map[aliasType.slice(9)]
92+
: isCorrectLang,
10293
)
10394
}
104-
}
105-
pos += token.length
95+
} else if (isCorrectLang && filter(type, pos)) match(content, pos)
10696
}
97+
pos += token.length
10798
}
10899
}
109100
const match = (token: string, pos: number) => {

solid-package/src/extensions/autocomplete/javascript/index.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { PrismEditor } from "../../../index.js"
44
import { braces, space } from "../../../languages/shared/index.js"
5+
import { TokenName } from "../../../prism/index.js"
56
import { getClosestToken } from "../../../utils/index.js"
67
import { Bracket } from "../../match-brackets"
78
import { Completion, CompletionContext, CompletionSource } from "../types.js"
@@ -206,9 +207,11 @@ const includedTypes = new Set([
206207
"property-access",
207208
"maybe-class-name",
208209
"generic-function",
210+
"expression",
209211
])
210212

211-
const identifierFilter = (type: string) => includedTypes.has(type)
213+
const identifierFilter = (value: string) => (type: TokenName, start: number) =>
214+
includedTypes.has(type) || (type == "tag" && value[start] == "<")
212215

213216
const identifierSearch = RegExp(`${identifierPattern}+`, "g")
214217

@@ -224,7 +227,13 @@ const completeIdentifiers = (identifiers?: Iterable<string>): CompletionSource<J
224227
? {
225228
from: getFrom(context),
226229
options: Array.from(
227-
findWords(context, editor, identifierFilter, identifierSearch, identifiers),
230+
findWords(
231+
context,
232+
editor,
233+
identifierFilter(editor.value),
234+
identifierSearch,
235+
identifiers,
236+
),
228237
label => ({
229238
label,
230239
icon: "text",
@@ -259,7 +268,13 @@ const jsCompletion = (scope: any, identifiers?: Iterable<string>): CompletionSou
259268
labels = scopeResult[1]
260269
} else completions = []
261270

262-
findWords(context, editor, identifierFilter, identifierSearch, identifiers).forEach(word => {
271+
findWords(
272+
context,
273+
editor,
274+
identifierFilter(editor.value),
275+
identifierSearch,
276+
identifiers,
277+
).forEach(word => {
263278
if (!labels?.has(word))
264279
completions.push({
265280
label: word,

solid-package/src/extensions/autocomplete/utils.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PrismEditor } from "../.."
2-
import { Token, TokenStream } from "../../prism"
2+
import { Token, TokenName, TokenStream } from "../../prism"
33
import { updateNode } from "../../utils/local"
44
import { matchTemplate } from "../search/search"
55
import { map } from "./tooltip"
@@ -53,7 +53,7 @@ const completeFromList = (options: Completion[]): CompletionSource<{ path: strin
5353
* @param filter Function used to filter tokens you want to search in. Is called with the
5454
* type of the token and its starting position. If the filter returns true, the token
5555
* will be searched.
56-
* @param pattern Pattern used to search for words.
56+
* @param pattern Pattern used to search for words. Must have the `g` flag.
5757
* @param init Words that should be completed even if they're not found in the document.
5858
* @param tokensOnly If `true` only the text of tokens whose `content` is a string will
5959
* be searched. If `false`, any string inside the {@link TokenStream} can be searched.
@@ -62,7 +62,7 @@ const completeFromList = (options: Completion[]): CompletionSource<{ path: strin
6262
const findWords = (
6363
context: CompletionContext,
6464
editor: PrismEditor,
65-
filter: (type: string, start: number) => boolean,
65+
filter: (type: TokenName, start: number) => boolean,
6666
pattern: RegExp,
6767
init?: Iterable<string>,
6868
tokensOnly?: boolean,
@@ -73,37 +73,28 @@ const findWords = (
7373
const search = (tokens: TokenStream, pos: number, isCorrectLang: boolean) => {
7474
let i = 0
7575
let token: string | Token
76-
if (isCorrectLang) {
77-
for (; (token = tokens[i++]); ) {
78-
if (typeof token == "string") {
79-
if (!tokensOnly) match(token, pos)
80-
} else {
81-
const type = token.type
82-
const content = token.content
83-
if ((token.alias || type).slice(0, 9) != "language-" && filter(type, pos)) {
84-
if (Array.isArray(content)) {
85-
search(content, pos, true)
86-
} else match(content, pos)
87-
}
88-
}
89-
pos += token.length
90-
}
91-
} else {
92-
for (; (token = tokens[i++]); ) {
93-
if (typeof token != "string") {
94-
const type = token.type
95-
const content = token.content
96-
if (Array.isArray(content)) {
97-
const aliasType = token.alias || type
76+
77+
for (; (token = tokens[i++]); ) {
78+
if (typeof token == "string") {
79+
if (!tokensOnly && isCorrectLang) match(token, pos)
80+
} else {
81+
const type = token.type
82+
const content = token.content
83+
const aliasType = token.alias || type
84+
85+
if (Array.isArray(content)) {
86+
if (!isCorrectLang || filter(type, pos)) {
9887
search(
9988
content,
10089
pos,
101-
aliasType.slice(0, 9) == "language-" ? definition == map[aliasType.slice(9)] : false,
90+
aliasType.slice(0, 9) == "language-"
91+
? definition == map[aliasType.slice(9)]
92+
: isCorrectLang,
10293
)
10394
}
104-
}
105-
pos += token.length
95+
} else if (isCorrectLang && filter(type, pos)) match(content, pos)
10696
}
97+
pos += token.length
10798
}
10899
}
109100
const match = (token: string, pos: number) => {

0 commit comments

Comments
 (0)