Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 28 additions & 1 deletion modules/generate/src/main/scala/generate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,34 @@ import langoustine.meta.*

import Render.*

given Render.Config(indents = Indentation(0), indentSize = IndentationSize(2))
given Render.Config(
indents = Indentation(0),
indentSize = IndentationSize(2),
// todo: these are currently in a global namespace, which is kinda bad?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

didn't spend enough time with the codebase to have a clue if a struct's renderer knows its FQN, so I went with this for now. It works by a miraculous stroke (of luck) as ByCells/ByDocumentAndCells both have the same structure.

anonNameOverrides = Map(
"MarkedString" -> List("MarkdownString", "CodeBlock"),
"NotebookDocumentFilter" -> List("ByType", "ByScheme", "ByPattern"),
"PrepareRenameResult" -> List(
"RangeAndPlaceholder",
"DefaultBehavior"
),
"TextDocumentContentChangeEvent" -> List("Partial", "Full"),
"TextDocumentFilter" -> List("ByLanguage", "ByScheme", "ByPattern"),
"ItemDefaults" -> List("InsertReplace"),
"Cells" -> List("TextContent"),
"NotebookDocumentSyncOptions" -> List("ByDocumentAndCells", "ByCells"),
"ByDocumentAndCells" -> List("Cell"),
"ByCells" -> List("Cell"),
"NotebookDocumentSyncRegistrationOptions" -> List(
"ByDocumentAndCells",
"ByCells"
),
"Requests" -> List("Range", "Delta"),
"SemanticTokensOptions" -> List("Range", "Delta"),
"SemanticTokensRegistrationOptions" -> List("Range", "Delta"),
"WorkspaceSymbol" -> List("External")
)
)

def inFile(s: String)(f: LineBuilder => Unit) =
val out = Render.LineBuilder()
Expand Down
19 changes: 16 additions & 3 deletions modules/generate/src/main/scala/render.scala
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,12 @@ class Render(manager: Manager, packageName: String = "langoustine.lsp"):
case other =>
val newType = other.traverse {
case stl: Type.StructureLiteralType =>
val newTypeName = "S" + inlineAnonymousStructures
val newTypeName = summon[Config].anonNameOverrides
.get(structure.name.value)
.fold("S" + inlineAnonymousStructures)(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

technically these S names don't happen anymore, but this is here to account for new types being added in future LSP versions and the maintainer not wanting to give them names immediately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually I think it's worth being strict here – better to fix the names once during update, than to expose S* and then have to break source compat renaming them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not completely unreasonable

_(inlineAnonymousStructures)
)

val newType: Type.ReferenceType = Type.ReferenceType(
TypeName(
structure.name.value + "." + newTypeName
Expand Down Expand Up @@ -981,7 +986,11 @@ class Render(manager: Manager, packageName: String = "langoustine.lsp"):
var inlineAnonymousStructures = 0
val newType = alias.`type`.traverse {
case stl: Type.StructureLiteralType =>
val newTypeName = "S" + inlineAnonymousStructures
val newTypeName = summon[Config].anonNameOverrides
.get(alias.name.value)
.fold("S" + inlineAnonymousStructures)(
_(inlineAnonymousStructures)
)
val newType: Type.ReferenceType = Type.ReferenceType(
TypeName(
alias.name.value + "." + newTypeName
Expand Down Expand Up @@ -1202,7 +1211,11 @@ object Render:
def appender: Config ?=> Appender = to(lb)
end LineBuilder

case class Config(indents: Indentation, indentSize: IndentationSize)
case class Config(
indents: Indentation,
indentSize: IndentationSize,
anonNameOverrides: Map[String, List[String]]
)

opaque type IndentationSize = Int
object IndentationSize extends OpaqueNum[IndentationSize]
Expand Down
98 changes: 49 additions & 49 deletions modules/lsp/src/main/scala/generated/aliases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,35 +148,35 @@ object aliases:
case c: Map[String, ujson.Value] => Some(c.asInstanceOf[s.type & Map[String, ujson.Value]])
case _ => Option.empty

opaque type MarkedString = (String | MarkedString.S0)
opaque type MarkedString = (String | MarkedString.MarkdownString)
object MarkedString extends codecs.aliases_MarkedString:
inline def apply(v: String): MarkedString = v
inline def apply(v: MarkedString.S0): MarkedString = v
inline def apply(v: MarkedString.MarkdownString): MarkedString = v

given Typeable[MarkedString] with
def unapply(s: Any): Option[s.type & MarkedString] =
s match
case c: String => Some(c.asInstanceOf[s.type & String])
case c: MarkedString.S0 => Some(c.asInstanceOf[s.type & MarkedString.S0])
case c: MarkedString.MarkdownString => Some(c.asInstanceOf[s.type & MarkedString.MarkdownString])
case _ => Option.empty
case class S0(
case class MarkdownString(
language: String,
value: String
)
object S0 extends codecs.aliases_MarkedString_S0Codec
object MarkdownString extends codecs.aliases_MarkedString_MarkdownStringCodec

opaque type NotebookDocumentFilter = (NotebookDocumentFilter.S0 | NotebookDocumentFilter.S1 | NotebookDocumentFilter.S2)
opaque type NotebookDocumentFilter = (NotebookDocumentFilter.ByType | NotebookDocumentFilter.ByScheme | NotebookDocumentFilter.ByPattern)
object NotebookDocumentFilter extends codecs.aliases_NotebookDocumentFilter:
inline def apply(v: NotebookDocumentFilter.S0): NotebookDocumentFilter = v
inline def apply(v: NotebookDocumentFilter.S1): NotebookDocumentFilter = v
inline def apply(v: NotebookDocumentFilter.S2): NotebookDocumentFilter = v
inline def apply(v: NotebookDocumentFilter.ByType): NotebookDocumentFilter = v
inline def apply(v: NotebookDocumentFilter.ByScheme): NotebookDocumentFilter = v
inline def apply(v: NotebookDocumentFilter.ByPattern): NotebookDocumentFilter = v

given Typeable[NotebookDocumentFilter] with
def unapply(s: Any): Option[s.type & NotebookDocumentFilter] =
s match
case c: NotebookDocumentFilter.S0 => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.S0])
case c: NotebookDocumentFilter.S1 => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.S1])
case c: NotebookDocumentFilter.S2 => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.S2])
case c: NotebookDocumentFilter.ByType => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.ByType])
case c: NotebookDocumentFilter.ByScheme => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.ByScheme])
case c: NotebookDocumentFilter.ByPattern => Some(c.asInstanceOf[s.type & NotebookDocumentFilter.ByPattern])
case _ => Option.empty
/**
* @param notebookType
Expand All @@ -189,12 +189,12 @@ object aliases:
* A glob pattern.

*/
case class S0(
case class ByType(
notebookType: String,
scheme: Opt[String] = Opt.empty,
pattern: Opt[String] = Opt.empty
)
object S0 extends codecs.aliases_NotebookDocumentFilter_S0Codec
object ByType extends codecs.aliases_NotebookDocumentFilter_ByTypeCodec
/**
* @param notebookType
* The type of the enclosing notebook.
Expand All @@ -206,12 +206,12 @@ object aliases:
* A glob pattern.

*/
case class S1(
case class ByScheme(
notebookType: Opt[String] = Opt.empty,
scheme: String,
pattern: Opt[String] = Opt.empty
)
object S1 extends codecs.aliases_NotebookDocumentFilter_S1Codec
object ByScheme extends codecs.aliases_NotebookDocumentFilter_BySchemeCodec
/**
* @param notebookType
* The type of the enclosing notebook.
Expand All @@ -223,12 +223,12 @@ object aliases:
* A glob pattern.

*/
case class S2(
case class ByPattern(
notebookType: Opt[String] = Opt.empty,
scheme: Opt[String] = Opt.empty,
pattern: String
)
object S2 extends codecs.aliases_NotebookDocumentFilter_S2Codec
object ByPattern extends codecs.aliases_NotebookDocumentFilter_ByPatternCodec

opaque type Pattern = String
object Pattern extends codecs.aliases_Pattern:
Expand All @@ -240,28 +240,28 @@ object aliases:
case c: String => Some(c.asInstanceOf[s.type & String])
case _ => Option.empty

opaque type PrepareRenameResult = (structures.Range | PrepareRenameResult.S0 | PrepareRenameResult.S1)
opaque type PrepareRenameResult = (structures.Range | PrepareRenameResult.RangeAndPlaceholder | PrepareRenameResult.DefaultBehavior)
object PrepareRenameResult extends codecs.aliases_PrepareRenameResult:
inline def apply(v: structures.Range): PrepareRenameResult = v
inline def apply(v: PrepareRenameResult.S0): PrepareRenameResult = v
inline def apply(v: PrepareRenameResult.S1): PrepareRenameResult = v
inline def apply(v: PrepareRenameResult.RangeAndPlaceholder): PrepareRenameResult = v
inline def apply(v: PrepareRenameResult.DefaultBehavior): PrepareRenameResult = v

given Typeable[PrepareRenameResult] with
def unapply(s: Any): Option[s.type & PrepareRenameResult] =
s match
case c: structures.Range => Some(c.asInstanceOf[s.type & structures.Range])
case c: PrepareRenameResult.S0 => Some(c.asInstanceOf[s.type & PrepareRenameResult.S0])
case c: PrepareRenameResult.S1 => Some(c.asInstanceOf[s.type & PrepareRenameResult.S1])
case c: PrepareRenameResult.RangeAndPlaceholder => Some(c.asInstanceOf[s.type & PrepareRenameResult.RangeAndPlaceholder])
case c: PrepareRenameResult.DefaultBehavior => Some(c.asInstanceOf[s.type & PrepareRenameResult.DefaultBehavior])
case _ => Option.empty
case class S0(
case class RangeAndPlaceholder(
range: structures.Range,
placeholder: String
)
object S0 extends codecs.aliases_PrepareRenameResult_S0Codec
case class S1(
object RangeAndPlaceholder extends codecs.aliases_PrepareRenameResult_RangeAndPlaceholderCodec
case class DefaultBehavior(
defaultBehavior: Boolean
)
object S1 extends codecs.aliases_PrepareRenameResult_S1Codec
object DefaultBehavior extends codecs.aliases_PrepareRenameResult_DefaultBehaviorCodec

opaque type ProgressToken = (Int | String)
object ProgressToken extends codecs.aliases_ProgressToken:
Expand All @@ -275,16 +275,16 @@ object aliases:
case c: String => Some(c.asInstanceOf[s.type & String])
case _ => Option.empty

opaque type TextDocumentContentChangeEvent = (TextDocumentContentChangeEvent.S0 | TextDocumentContentChangeEvent.S1)
opaque type TextDocumentContentChangeEvent = (TextDocumentContentChangeEvent.Partial | TextDocumentContentChangeEvent.Full)
object TextDocumentContentChangeEvent extends codecs.aliases_TextDocumentContentChangeEvent:
inline def apply(v: TextDocumentContentChangeEvent.S0): TextDocumentContentChangeEvent = v
inline def apply(v: TextDocumentContentChangeEvent.S1): TextDocumentContentChangeEvent = v
inline def apply(v: TextDocumentContentChangeEvent.Partial): TextDocumentContentChangeEvent = v
inline def apply(v: TextDocumentContentChangeEvent.Full): TextDocumentContentChangeEvent = v

given Typeable[TextDocumentContentChangeEvent] with
def unapply(s: Any): Option[s.type & TextDocumentContentChangeEvent] =
s match
case c: TextDocumentContentChangeEvent.S0 => Some(c.asInstanceOf[s.type & TextDocumentContentChangeEvent.S0])
case c: TextDocumentContentChangeEvent.S1 => Some(c.asInstanceOf[s.type & TextDocumentContentChangeEvent.S1])
case c: TextDocumentContentChangeEvent.Partial => Some(c.asInstanceOf[s.type & TextDocumentContentChangeEvent.Partial])
case c: TextDocumentContentChangeEvent.Full => Some(c.asInstanceOf[s.type & TextDocumentContentChangeEvent.Full])
case _ => Option.empty
/**
* @param range
Expand All @@ -299,34 +299,34 @@ object aliases:
* The new text for the provided range.

*/
case class S0(
case class Partial(
range: structures.Range,
rangeLength: Opt[runtime.uinteger] = Opt.empty,
text: String
)
object S0 extends codecs.aliases_TextDocumentContentChangeEvent_S0Codec
object Partial extends codecs.aliases_TextDocumentContentChangeEvent_PartialCodec
/**
* @param text
* The new text of the whole document.

*/
case class S1(
case class Full(
text: String
)
object S1 extends codecs.aliases_TextDocumentContentChangeEvent_S1Codec
object Full extends codecs.aliases_TextDocumentContentChangeEvent_FullCodec

opaque type TextDocumentFilter = (TextDocumentFilter.S0 | TextDocumentFilter.S1 | TextDocumentFilter.S2)
opaque type TextDocumentFilter = (TextDocumentFilter.ByLanguage | TextDocumentFilter.ByScheme | TextDocumentFilter.ByPattern)
object TextDocumentFilter extends codecs.aliases_TextDocumentFilter:
inline def apply(v: TextDocumentFilter.S0): TextDocumentFilter = v
inline def apply(v: TextDocumentFilter.S1): TextDocumentFilter = v
inline def apply(v: TextDocumentFilter.S2): TextDocumentFilter = v
inline def apply(v: TextDocumentFilter.ByLanguage): TextDocumentFilter = v
inline def apply(v: TextDocumentFilter.ByScheme): TextDocumentFilter = v
inline def apply(v: TextDocumentFilter.ByPattern): TextDocumentFilter = v

given Typeable[TextDocumentFilter] with
def unapply(s: Any): Option[s.type & TextDocumentFilter] =
s match
case c: TextDocumentFilter.S0 => Some(c.asInstanceOf[s.type & TextDocumentFilter.S0])
case c: TextDocumentFilter.S1 => Some(c.asInstanceOf[s.type & TextDocumentFilter.S1])
case c: TextDocumentFilter.S2 => Some(c.asInstanceOf[s.type & TextDocumentFilter.S2])
case c: TextDocumentFilter.ByLanguage => Some(c.asInstanceOf[s.type & TextDocumentFilter.ByLanguage])
case c: TextDocumentFilter.ByScheme => Some(c.asInstanceOf[s.type & TextDocumentFilter.ByScheme])
case c: TextDocumentFilter.ByPattern => Some(c.asInstanceOf[s.type & TextDocumentFilter.ByPattern])
case _ => Option.empty
/**
* @param language
Expand All @@ -339,12 +339,12 @@ object aliases:
* A glob pattern, like **​.{ts,js}. See TextDocumentFilter for examples.

*/
case class S0(
case class ByLanguage(
language: String,
scheme: Opt[String] = Opt.empty,
pattern: Opt[String] = Opt.empty
)
object S0 extends codecs.aliases_TextDocumentFilter_S0Codec
object ByLanguage extends codecs.aliases_TextDocumentFilter_ByLanguageCodec
/**
* @param language
* A language id, like `typescript`.
Expand All @@ -356,12 +356,12 @@ object aliases:
* A glob pattern, like **​.{ts,js}. See TextDocumentFilter for examples.

*/
case class S1(
case class ByScheme(
language: Opt[String] = Opt.empty,
scheme: String,
pattern: Opt[String] = Opt.empty
)
object S1 extends codecs.aliases_TextDocumentFilter_S1Codec
object ByScheme extends codecs.aliases_TextDocumentFilter_BySchemeCodec
/**
* @param language
* A language id, like `typescript`.
Expand All @@ -373,12 +373,12 @@ object aliases:
* A glob pattern, like **​.{ts,js}. See TextDocumentFilter for examples.

*/
case class S2(
case class ByPattern(
language: Opt[String] = Opt.empty,
scheme: Opt[String] = Opt.empty,
pattern: String
)
object S2 extends codecs.aliases_TextDocumentFilter_S2Codec
object ByPattern extends codecs.aliases_TextDocumentFilter_ByPatternCodec

opaque type WorkspaceDocumentDiagnosticReport = (structures.WorkspaceFullDocumentDiagnosticReport | structures.WorkspaceUnchangedDocumentDiagnosticReport)
object WorkspaceDocumentDiagnosticReport extends codecs.aliases_WorkspaceDocumentDiagnosticReport:
Expand Down
Loading