From 16441bc330ae9de7802350500078aa1e69cd42e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Thu, 25 Jul 2024 13:27:54 -0400 Subject: [PATCH 1/2] Add syntax help over and placeholder help texts --- src/Code/Syntax/SyntaxSegment.elm | 124 ++++++++++++++++++- src/Code/Syntax/SyntaxSegmentHelp.elm | 164 ++++++++++++++++++++++++++ 2 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 src/Code/Syntax/SyntaxSegmentHelp.elm diff --git a/src/Code/Syntax/SyntaxSegment.elm b/src/Code/Syntax/SyntaxSegment.elm index 5133fbfe..5c8de2f9 100644 --- a/src/Code/Syntax/SyntaxSegment.elm +++ b/src/Code/Syntax/SyntaxSegment.elm @@ -5,6 +5,7 @@ import Code.FullyQualifiedName as FQN exposing (FQN) import Code.Hash as Hash exposing (Hash) import Code.HashQualified as HQ import Code.Syntax.Linked exposing (Linked(..)) +import Code.Syntax.SyntaxSegmentHelp as SyntaxSegmentHelp import Html exposing (Html, span, text) import Html.Attributes exposing (class) import Html.Events exposing (onMouseEnter, onMouseLeave) @@ -58,7 +59,7 @@ type SyntaxType | UseSuffix -- TODO: Should this be a HashQualified ? | HashQualifier String - -- ! ' + -- ' () | DelayForceChar -- ? , ` [ ] @ | -- Currently not all commas in the pretty-print output are marked up as DelimiterChar - we miss @@ -317,8 +318,125 @@ view linked ((SyntaxSegment sType sText) as segment) = helpForSegment : SyntaxSegment -> Maybe (Html msg) -helpForSegment _ = - Nothing +helpForSegment (SyntaxSegment syntaxType segmentText) = + let + segmentText_ = + String.trim segmentText + in + case syntaxType of + ControlKeyword -> + case segmentText_ of + "let" -> + Just (text "") + + "handle" -> + Just (text "") + + "in" -> + Just (text "") + + "where" -> + Just (text "") + + "match" -> + Just SyntaxSegmentHelp.matchWith + + "with" -> + Just SyntaxSegmentHelp.matchWith + + "cases" -> + Just SyntaxSegmentHelp.cases + + "if" -> + Just SyntaxSegmentHelp.ifElse + + "then" -> + Just SyntaxSegmentHelp.ifElse + + "else" -> + Just SyntaxSegmentHelp.ifElse + + "and" -> + Just (text "") + + "or" -> + Just (text "") + + _ -> + Nothing + + UseKeyword -> + Just SyntaxSegmentHelp.use + + UsePrefix -> + Just SyntaxSegmentHelp.use + + UseSuffix -> + Just SyntaxSegmentHelp.use + + NumericLiteral -> + Just SyntaxSegmentHelp.numericLiteral + + TextLiteral -> + Just SyntaxSegmentHelp.textLiteral + + BytesLiteral -> + Just SyntaxSegmentHelp.bytesLiteral + + CharLiteral -> + Just SyntaxSegmentHelp.charLiteral + + Op Cons -> + Just SyntaxSegmentHelp.cons + + Op Snoc -> + Just SyntaxSegmentHelp.snoc + + Op Concat -> + Just SyntaxSegmentHelp.concat + + Unit -> + Just SyntaxSegmentHelp.unit + + DataTypeModifier -> + Just SyntaxSegmentHelp.uniqueKeyword + + AbilityBraces -> + Just SyntaxSegmentHelp.abilityBraces + + TypeOperator -> + Just SyntaxSegmentHelp.typeOperator + + TypeAscriptionColon -> + Just SyntaxSegmentHelp.typeAscriptionColon + + DataTypeKeyword -> + case segmentText_ of + "type" -> + Just SyntaxSegmentHelp.typeKeyword + + "ability" -> + Just SyntaxSegmentHelp.abilityKeyword + + _ -> + Nothing + + DataTypeParams -> + Just SyntaxSegmentHelp.typeParams + + LinkKeyword -> + case segmentText_ of + "typeLink" -> + Just SyntaxSegmentHelp.typeLink + + "termLink" -> + Just SyntaxSegmentHelp.termLink + + _ -> + Nothing + + _ -> + Nothing diff --git a/src/Code/Syntax/SyntaxSegmentHelp.elm b/src/Code/Syntax/SyntaxSegmentHelp.elm new file mode 100644 index 00000000..0a17b272 --- /dev/null +++ b/src/Code/Syntax/SyntaxSegmentHelp.elm @@ -0,0 +1,164 @@ +{- A collection of syntax help texts used in tooltips when hovering Unison + syntax like `cases` or `match` +-} + + +module Code.Syntax.SyntaxSegmentHelp exposing (..) + +import Html exposing (Html, text) + + + +-- Literals + + +numericLiteral : Html msg +numericLiteral = + text "Something something" + + +textLiteral : Html msg +textLiteral = + text "Something something" + + +bytesLiteral : Html msg +bytesLiteral = + text "Something something" + + +charLiteral : Html msg +charLiteral = + text "Something something" + + + +-- List + + +cons : Html msg +cons = + text "Something something" + + +snoc : Html msg +snoc = + text "Something something" + + + +-- Types + + +typeKeyword : Html msg +typeKeyword = + text "Something something" + + +typeParams : Html msg +typeParams = + text "Something something" + + +typeOperator : Html msg +typeOperator = + text "Something something" + + +typeAscriptionColon : Html msg +typeAscriptionColon = + text "Something something" + + + +-- Links + + +typeLink : Html msg +typeLink = + text "Something something" + + +termLink : Html msg +termLink = + text "Something something" + + + +-- Pattern matching + + +matchWith : Html msg +matchWith = + text "Something something pattern matching" + + +cases : Html msg +cases = + text "Something something pattern matching" + + + +-- Conditionals + + +ifElse : Html msg +ifElse = + text "" + + + +-- Use/Imports + + +use : Html msg +use = + text "Similar to an import statement" + + + +-- Abilities + + +abilityKeyword : Html msg +abilityKeyword = + text "Ability" + + +abilityBraces : Html msg +abilityBraces = + text "Ability" + + +handle : Html msg +handle = + text "Handles an Ability" + + +thunkQuote : Html msg +thunkQuote = + text "Denotes a thunk" + + +forceParens : Html msg +forceParens = + text "Runs a thunk" + + + +-- Misc + + +concat : Html msg +concat = + text "Something something" + + +unit : Html msg +unit = + text "Something something" + + +uniqueKeyword : Html msg +uniqueKeyword = + text "Something something" From 37f5fab23e88b404c7f06b1dc7aa3a776a67768a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Thu, 25 Jul 2024 14:52:29 -0400 Subject: [PATCH 2/2] Update with syntax text from rlmark --- src/Code/Syntax/SyntaxSegment.elm | 65 ++++++++++++++----- src/Code/Syntax/SyntaxSegmentHelp.elm | 92 ++++++++++++++++----------- 2 files changed, 104 insertions(+), 53 deletions(-) diff --git a/src/Code/Syntax/SyntaxSegment.elm b/src/Code/Syntax/SyntaxSegment.elm index 5c8de2f9..d987ef00 100644 --- a/src/Code/Syntax/SyntaxSegment.elm +++ b/src/Code/Syntax/SyntaxSegment.elm @@ -326,23 +326,18 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = case syntaxType of ControlKeyword -> case segmentText_ of - "let" -> - Just (text "") - "handle" -> - Just (text "") - - "in" -> - Just (text "") + Just SyntaxSegmentHelp.handleWith "where" -> - Just (text "") + Just SyntaxSegmentHelp.abilityWhere "match" -> Just SyntaxSegmentHelp.matchWith "with" -> - Just SyntaxSegmentHelp.matchWith + -- We don't know if its match...with or handle...with + Nothing "cases" -> Just SyntaxSegmentHelp.cases @@ -356,11 +351,19 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = "else" -> Just SyntaxSegmentHelp.ifElse - "and" -> - Just (text "") + "do" -> + Just SyntaxSegmentHelp.doKeyword - "or" -> - Just (text "") + _ -> + Nothing + + DelayForceChar -> + case segmentText_ of + "'" -> + Just SyntaxSegmentHelp.delayed + + "()" -> + Just SyntaxSegmentHelp.forceParens _ -> Nothing @@ -378,7 +381,11 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = Just SyntaxSegmentHelp.numericLiteral TextLiteral -> - Just SyntaxSegmentHelp.textLiteral + if String.startsWith "\"\"\"" segmentText_ then + Just SyntaxSegmentHelp.textLiteralMultiline + + else + Just SyntaxSegmentHelp.textLiteral BytesLiteral -> Just SyntaxSegmentHelp.bytesLiteral @@ -399,13 +406,26 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = Just SyntaxSegmentHelp.unit DataTypeModifier -> - Just SyntaxSegmentHelp.uniqueKeyword + case segmentText_ of + "unique" -> + Just SyntaxSegmentHelp.uniqueKeyword + + "structural" -> + Just SyntaxSegmentHelp.structuralKeyword + + _ -> + Nothing AbilityBraces -> Just SyntaxSegmentHelp.abilityBraces TypeOperator -> - Just SyntaxSegmentHelp.typeOperator + case segmentText_ of + "forall" -> + Just SyntaxSegmentHelp.typeForall + + _ -> + Nothing TypeAscriptionColon -> Just SyntaxSegmentHelp.typeAscriptionColon @@ -416,7 +436,7 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = Just SyntaxSegmentHelp.typeKeyword "ability" -> - Just SyntaxSegmentHelp.abilityKeyword + Just SyntaxSegmentHelp.abilityWhere _ -> Nothing @@ -424,6 +444,17 @@ helpForSegment (SyntaxSegment syntaxType segmentText) = DataTypeParams -> Just SyntaxSegmentHelp.typeParams + DelimiterChar -> + case segmentText_ of + "@" -> + Just SyntaxSegmentHelp.asPattern + + "termLink" -> + Just SyntaxSegmentHelp.termLink + + _ -> + Nothing + LinkKeyword -> case segmentText_ of "typeLink" -> diff --git a/src/Code/Syntax/SyntaxSegmentHelp.elm b/src/Code/Syntax/SyntaxSegmentHelp.elm index 0a17b272..f0ae55ef 100644 --- a/src/Code/Syntax/SyntaxSegmentHelp.elm +++ b/src/Code/Syntax/SyntaxSegmentHelp.elm @@ -14,22 +14,27 @@ import Html exposing (Html, text) numericLiteral : Html msg numericLiteral = - text "Something something" + text "A numeric literal. Some common numeric types are `Nat`: `24`, `Float`: `4.5`, and `Int`: `-60`." textLiteral : Html msg textLiteral = - text "Something something" + text "The value inside of the double quotes is a `Text` literal." + + +textLiteralMultiline : Html msg +textLiteralMultiline = + text "A multi-line `Text` literal. These values preserve whitespace and line breaks. " bytesLiteral : Html msg bytesLiteral = - text "Something something" + text "A `Bytes` literal. An arbitrary-length 8-bit byte sequence." charLiteral : Html msg charLiteral = - text "Something something" + text "A `Char` literal: `Char` is the type for a single Unicode character." @@ -38,12 +43,12 @@ charLiteral = cons : Html msg cons = - text "Something something" + text "Extracts the head element of a list from its tail and binds each to a variable, for example: `head +: tail`. " snoc : Html msg snoc = - text "Something something" + text "Extracts the last element of a list and binds the two segments to variables, for example: `prefix :+ last`." @@ -52,22 +57,32 @@ snoc = typeKeyword : Html msg typeKeyword = - text "Something something" + text "Introduces a type definition. By default, `type` introduces a unique type: one which will be referenced by its name." typeParams : Html msg typeParams = - text "Something something" + text "A lowercase value in a type signature introduces a type parameter " -typeOperator : Html msg -typeOperator = - text "Something something" +typeForall : Html msg +typeForall = + text "`forall` describes a type that is universally quantified." typeAscriptionColon : Html msg typeAscriptionColon = - text "Something something" + text "In a type signature, the colon separates the name of a function from its type. The colon can be read as \"has type\"." + + +uniqueKeyword : Html msg +uniqueKeyword = + text "Introduces a nominal type: one which will be referenced by its name, as opposed to one which is identified by its structure." + + +structuralKeyword : Html msg +structuralKeyword = + text "Introduces a structural type: one which is identified and unique to its structure, not by its name." @@ -76,12 +91,12 @@ typeAscriptionColon = typeLink : Html msg typeLink = - text "Something something" + text "`typeLink` takes a Unison type as an argument and turns it into a value of `Link.Type`. Most commonly used in error messages or the `Doc` type." termLink : Html msg termLink = - text "Something something" + text "`termLink` takes a Unison term as an argument and creates a value of `Link.Term`." @@ -90,12 +105,17 @@ termLink = matchWith : Html msg matchWith = - text "Something something pattern matching" + text "Introduces a way to check a value against a pattern. The expression to the right of `match` is the target value of the match, and the statement(s) following `with` are the potential patterns." cases : Html msg cases = - text "Something something pattern matching" + text "`cases` is syntactic sugar for a `match statement`. For example, `match a with a1` could be shortened `cases a1`." + + +asPattern : Html msg +asPattern = + text "In a pattern match,`@` is an \"as-pattern\". It is a way of binding a variable to an element in the pattern match. The value to the left of the `@` is the variable name and the value to the right is what the variable references." @@ -104,7 +124,7 @@ cases = ifElse : Html msg ifElse = - text "" + text "A conditional statement. If the `Boolean` expression argument is `true`, the first branch of the statement will be executed, if it is `false`, the second branch will be run instead. " @@ -113,36 +133,41 @@ ifElse = use : Html msg use = - text "Similar to an import statement" + text "A `use` clause tells Unison to allow identifiers from a given namespace to be used without prefixing in the lexical scope where the use clause appears." -- Abilities -abilityKeyword : Html msg -abilityKeyword = - text "Ability" +abilityWhere : Html msg +abilityWhere = + text "Introduces an ability definition. The name of the ability follows the keyword and the operations that the ability can perform are listed as function signatures after the `where` keyword. " abilityBraces : Html msg abilityBraces = - text "Ability" + text "Defines the set of abilities that a function can perform. The abilities will appear in a comma-delimited list. " + + +handleWith : Html msg +handleWith = + text "The `handle` keyword indicates that a function is an ability handler. The first argument is an expression performing a particular ability to handle and what follows dictates how the ability should be handled." -handle : Html msg -handle = - text "Handles an Ability" +doKeyword : Html msg +doKeyword = + text "`do` introduces a delayed computation, something with the form `() -> a`." -thunkQuote : Html msg -thunkQuote = - text "Denotes a thunk" +delayed : Html msg +delayed = + text "In a type signature, `'` indicates an argument is delayed, so `'`a means `() -> a`. In a function body, `'` indicates that the term immediately to the right is delayed. " forceParens : Html msg forceParens = - text "Runs a thunk" + text "`()` forces the evaluation of a delayed computation." @@ -151,14 +176,9 @@ forceParens = concat : Html msg concat = - text "Something something" + text "Matches a list that is composed of the concatenation of two sub-lists. At least one of the sub-lists must be a pattern with a known length, commonly indicated by square brackets: `[a, b] ++ tail`." unit : Html msg unit = - text "Something something" - - -uniqueKeyword : Html msg -uniqueKeyword = - text "Something something" + text "Unit is the type which represents a no-argument tuple `()`. Its one data constructor is also written `()`."