From 2478e627e882620b858585e48cfab0bfe89a6440 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Sat, 10 Aug 2024 22:03:02 +0200 Subject: [PATCH] derp --- .../CellInput/LiveDocsFromCursor.js | 21 +++++++++-------- .../components/CellInput/lezer_template.js | 14 ++++++----- frontend/components/CellInput/mixedParsers.js | 9 +------- .../components/CellInput/pkg_bubble_plugin.js | 4 ++-- .../CellInput/pluto_autocomplete.js | 14 +++++------ .../CellInput/scopestate_statefield.js | 23 ++++++++++--------- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/frontend/components/CellInput/LiveDocsFromCursor.js b/frontend/components/CellInput/LiveDocsFromCursor.js index a2cd0ffdbf..0c1b67b0a5 100644 --- a/frontend/components/CellInput/LiveDocsFromCursor.js +++ b/frontend/components/CellInput/LiveDocsFromCursor.js @@ -2,7 +2,7 @@ import { EditorState, syntaxTree } from "../../imports/CodemirrorPlutoSetup.js" import { ScopeStateField } from "./scopestate_statefield.js" let get_root_variable_from_expression = (cursor) => { - if (cursor.name === "SubscriptExpression") { + if (cursor.name === "IndexExpression") { cursor.firstChild() return get_root_variable_from_expression(cursor) } @@ -20,12 +20,13 @@ let get_root_variable_from_expression = (cursor) => { let VALID_DOCS_TYPES = [ "Identifier", "FieldExpression", - "SubscriptExpression", + "IndexExpression", "MacroFieldExpression", "MacroIdentifier", "Operator", - "Definition", - "ParameterizedIdentifier", + "TypeHead", + "Signature", + "ParametrizedExpression", ] let keywords_that_have_docs_and_are_cool = [ "import", @@ -49,12 +50,12 @@ let is_docs_searchable = (/** @type {import("../../imports/CodemirrorPlutoSetup. } else if (VALID_DOCS_TYPES.includes(cursor.name)) { if (cursor.firstChild()) { do { - // Numbers themselves can't be docs searched, but using numbers inside SubscriptExpression can be. - if (cursor.name === "Number") { + // Numbers themselves can't be docs searched, but using numbers inside IndexExpression can be. + if (cursor.name === "IntegerLiteral" || cursor.name === "FloatLiteral") { continue } // This is for the VERY specific case like `Vector{Int}(1,2,3,4) which I want to yield `Vector{Int}` - if (cursor.name === "TypeArgumentList") { + if (cursor.name === "BraceExpression") { continue } if (cursor.name === "FieldName" || cursor.name === "MacroName" || cursor.name === "MacroFieldName") { @@ -129,7 +130,7 @@ export let get_selected_doc_from_state = (/** @type {EditorState} */ state, verb // - Struct name is useless: you are looking at the definition // - Properties are just named, not in the workspace or anything // Only thing we do want, are types and the right hand side of `=`'s. - if (parents.includes("AssignmentExpression") && parents.indexOf("AssignmentExpression") < index_of_struct_in_parents) { + if (parents.includes("binding") && parents.indexOf("binding") < index_of_struct_in_parents) { // We're inside a `... = ...` inside the struct } else if (parents.includes("TypedExpression") && parents.indexOf("TypedExpression") < index_of_struct_in_parents) { // We're inside a `x::X` inside the struct @@ -229,7 +230,7 @@ export let get_selected_doc_from_state = (/** @type {EditorState} */ state, verb } // `a = 1` would yield `=`, `a += 1` would yield `+=` - if (cursor.name === "AssignmentExpression") { + if (cursor.name === "binding") { let end_of_first = cursor.node.firstChild.to let beginning_of_last = cursor.node.lastChild.from return state.doc.sliceString(end_of_first, beginning_of_last).trim() @@ -320,7 +321,7 @@ export let get_selected_doc_from_state = (/** @type {EditorState} */ state, verb return undefined } // If we are expanding to an AssigmentExpression, we DONT want to show `=` - if (parent.name === "AssignmentExpression") { + if (parent.name === "binding") { return undefined } } finally { diff --git a/frontend/components/CellInput/lezer_template.js b/frontend/components/CellInput/lezer_template.js index edfdcaeab5..9564a5ad38 100644 --- a/frontend/components/CellInput/lezer_template.js +++ b/frontend/components/CellInput/lezer_template.js @@ -261,7 +261,7 @@ export let match_template = (haystack_cursor, template, matches, verbose = false // Skip comments // TODO This is, I think, one of the few julia-only things right now..... // .... Any sane way to factor this out? - while (haystack_cursor.name === "Comment" || haystack_cursor.name === "BlockComment") { + while (haystack_cursor.name === "LineComment" || haystack_cursor.name === "BlockComment") { if (!haystack_cursor.nextSibling()) break } @@ -466,7 +466,11 @@ export let to_template = function* (julia_code_object) { } }) if (unused_substitutions.length > 0) { - throw new Error(`Some substitutions not applied, this means it couldn't be matched to a AST position: ${JSON.stringify(unused_substitutions)}`) + throw new Error( + `Some substitutions not applied, this means it couldn't be matched to a AST position.\n\nUnused substitutions: ${JSON.stringify( + unused_substitutions + )}\n` + ) } return result } else if (typeof julia_code_object === "function") { @@ -837,7 +841,7 @@ export const t = /** @type {const} */ ({ yield "69" return { pattern: function Number(haystack, matches, verbose = false) { - return haystack != null && narrow_name(haystack) === "Number" + return haystack != null && (narrow_name(haystack) === "IntegerLiteral" || narrow_name(haystack) === "FloatLiteral") }, } }, @@ -846,9 +850,7 @@ export const t = /** @type {const} */ ({ yield `"A113"` return { pattern: function String(haystack, matches, verbose = false) { - return ( - haystack != null && (narrow_name(haystack) === "StringWithoutInterpolation" || narrow_name(haystack) === "TripleStringWithoutInterpolation") - ) + return haystack != null && (narrow_name(haystack) === "StringLiteral" || narrow_name(haystack) === "NsStringLiteral") }, } }, diff --git a/frontend/components/CellInput/mixedParsers.js b/frontend/components/CellInput/mixedParsers.js index 11898e0539..62659fdec8 100644 --- a/frontend/components/CellInput/mixedParsers.js +++ b/frontend/components/CellInput/mixedParsers.js @@ -80,14 +80,7 @@ const overlayHack = (overlay, input) => { }) } -const STRING_NODE_NAMES = new Set([ - "TripleString", - "String", - "CommandString", - "TripleStringWithoutInterpolation", - "StringWithoutInterpolation", - "CommandStringWithoutInterpolation", -]) +export const STRING_NODE_NAMES = new Set(["StringLiteral", "CommandLiteral", "NsStringLiteral", "NsCommandLiteral"]) const juliaWrapper = parseMixed((node, input) => { if (!STRING_NODE_NAMES.has(node.type.name)) { diff --git a/frontend/components/CellInput/pkg_bubble_plugin.js b/frontend/components/CellInput/pkg_bubble_plugin.js index fcab9e6a8a..f38a5e9dee 100644 --- a/frontend/components/CellInput/pkg_bubble_plugin.js +++ b/frontend/components/CellInput/pkg_bubble_plugin.js @@ -39,7 +39,7 @@ function find_import_statements({ doc, tree, from, to }) { quotelevel++ } // `$(...)` when inside quote - if (cursor.name === "InterpolationExpression") { + if (cursor.name === "InterpExpression") { quotelevel-- } if (quotelevel !== 0) return @@ -160,7 +160,7 @@ function find_import_statements({ doc, tree, from, to }) { if (cursor.name === "QuoteExpression" || cursor.name === "QuoteStatement") { quotelevel-- } - if (cursor.name === "InterpolationExpression") { + if (cursor.name === "InterpExpression") { quotelevel++ } }, diff --git a/frontend/components/CellInput/pluto_autocomplete.js b/frontend/components/CellInput/pluto_autocomplete.js index edca7a4aee..e5d7b6cc67 100644 --- a/frontend/components/CellInput/pluto_autocomplete.js +++ b/frontend/components/CellInput/pluto_autocomplete.js @@ -7,6 +7,7 @@ import { ScopeStateField } from "./scopestate_statefield.js" import { open_bottom_right_panel } from "../BottomRightPanel.js" import { ENABLE_CM_AUTOCOMPLETE_ON_TYPE } from "../CellInput.js" import { GlobalDefinitionsFacet } from "./go_to_definition_plugin.js" +import { STRING_NODE_NAMES } from "./mixedParsers.js" let { autocompletion, completionKeymap, completionStatus, acceptCompletion, selectedCompletion } = autocomplete @@ -128,7 +129,7 @@ const match_symbol_complete = (/** @type {autocomplete.CompletionContext} */ ctx function match_string_complete(state, pos) { const tree = syntaxTree(state) const node = tree.resolve(pos) - if (node == null || (node.name !== "TripleString" && node.name !== "String")) { + if (node == null || !STRING_NODE_NAMES.has(node.name)) { return false } return true @@ -166,7 +167,7 @@ const julia_code_completions_to_cm = (/** @type {PlutoRequestAutocomplete} */ request_autocomplete) => async (/** @type {autocomplete.CompletionContext} */ ctx) => { if (match_special_symbol_complete(ctx)) return null if (!ctx.explicit && writing_variable_name_or_keyword(ctx)) return null - if (!ctx.explicit && ctx.tokenBefore(["Number", "Comment", "String", "TripleString"]) != null) return null + if (!ctx.explicit && ctx.tokenBefore(["IntegerLiteral", "FloatLiteral", "LineComment", "BlockComment", ...STRING_NODE_NAMES]) != null) return null let to_complete = /** @type {String} */ (ctx.state.sliceDoc(0, ctx.pos)) @@ -270,13 +271,12 @@ const julia_code_completions_to_cm = const complete_anyword = async (/** @type {autocomplete.CompletionContext} */ ctx) => { if (match_special_symbol_complete(ctx)) return null if (!ctx.explicit && writing_variable_name_or_keyword(ctx)) return null - if (!ctx.explicit && ctx.tokenBefore(["Number", "Comment", "String", "TripleString"]) != null) return null + if (!ctx.explicit && ctx.tokenBefore(["IntegerLiteral", "FloatLiteral", "LineComment", "BlockComment", ...STRING_NODE_NAMES]) != null) return null const results_from_cm = await autocomplete.completeAnyWord(ctx) if (results_from_cm === null) return null - const last_token = ctx.tokenBefore(["Identifier", "Number"]) - if (last_token == null || last_token.type?.name === "Number") return null + if (ctx.tokenBefore(["Identifier", "IntegerLiteral", "FloatLiteral"])) return null return { from: results_from_cm.from, @@ -321,7 +321,7 @@ const writing_variable_name_or_keyword = (/** @type {autocomplete.CompletionCont const global_variables_completion = async (/** @type {autocomplete.CompletionContext} */ ctx) => { if (match_special_symbol_complete(ctx)) return null if (!ctx.explicit && writing_variable_name_or_keyword(ctx)) return null - if (!ctx.explicit && ctx.tokenBefore(["Number", "Comment", "String", "TripleString"]) != null) return null + if (!ctx.explicit && ctx.tokenBefore(["IntegerLiteral", "FloatLiteral", "LineComment", "BlockComment", ...STRING_NODE_NAMES]) != null) return null const globals = ctx.state.facet(GlobalDefinitionsFacet) @@ -438,7 +438,7 @@ const special_symbols_completion = (/** @type {() => Promise} * return async (/** @type {autocomplete.CompletionContext} */ ctx) => { if (!match_special_symbol_complete(ctx)) return null if (!ctx.explicit && writing_variable_name_or_keyword(ctx)) return null - if (!ctx.explicit && ctx.tokenBefore(["Number", "Comment"]) != null) return null + if (!ctx.explicit && ctx.tokenBefore(["IntegerLiteral", "FloatLiteral", "LineComment", "BlockComment"]) != null) return null const result = await get_special_symbols() return await autocomplete.completeFromList(result ?? [])(ctx) diff --git a/frontend/components/CellInput/scopestate_statefield.js b/frontend/components/CellInput/scopestate_statefield.js index 2478d5ba65..027d9035b7 100644 --- a/frontend/components/CellInput/scopestate_statefield.js +++ b/frontend/components/CellInput/scopestate_statefield.js @@ -49,7 +49,7 @@ let merge_scope_state = (a, b) => { /** @param {TreeCursor} cursor */ let search_for_interpolations = function* (cursor) { for (let child of child_cursors(cursor)) { - if (child.name === "InterpolationExpression") { + if (child.name === "InterpExpression") { yield cursor } else if (child.name === "QuoteExpression" || child.name === "QuoteStatement") { for (let child_child of search_for_interpolations(child)) { @@ -470,36 +470,37 @@ export let explore_variable_usage = ( // Doing these checks in front seems to speed things up a bit. if ( cursor.type.is("keyword") || - cursor.name === "SourceFile" || - cursor.name === "BooleanLiteral" || - cursor.name === "Character" || + cursor.name === "Program" || + cursor.name === "BoolLiteral" || + cursor.name === "CharLiteral" || cursor.name === "String" || - cursor.name === "Number" || + cursor.name === "IntegerLiteral" || + cursor.name === "FloatLiteral" || cursor.name === "Comment" || cursor.name === "BinaryExpression" || cursor.name === "Operator" || cursor.name === "MacroArgumentList" || cursor.name === "ReturnStatement" || - cursor.name === "BareTupleExpression" || - cursor.name === "ParenthesizedExpression" || + cursor.name === "OpenTuple" || + cursor.name === "ParenExpression" || cursor.name === "Type" || - cursor.name === "InterpolationExpression" || + cursor.name === "InterpExpression" || cursor.name === "SpreadExpression" || cursor.name === "CompoundExpression" || cursor.name === "ParameterizedIdentifier" || - cursor.name === "TypeArgumentList" || + cursor.name === "BraceExpression" || cursor.name === "TernaryExpression" || cursor.name === "Coefficient" || cursor.name === "TripleString" || cursor.name === "RangeExpression" || - cursor.name === "SubscriptExpression" || + cursor.name === "IndexExpression" || cursor.name === "UnaryExpression" || cursor.name === "ConstStatement" || cursor.name === "GlobalStatement" || cursor.name === "ContinueStatement" || cursor.name === "MatrixExpression" || cursor.name === "MatrixRow" || - cursor.name === "ArrayExpression" + cursor.name === "VectorExpression" ) { for (let subcursor of child_cursors(cursor)) { scopestate = explore_variable_usage(subcursor, doc, scopestate, verbose)