[TSP] Adding source file, namespace, scalar, operation, and references.#371
[TSP] Adding source file, namespace, scalar, operation, and references.#371glecaros wants to merge 6 commits intoalloy-framework:feature/typespecfrom
Conversation
Adding namespace and source file components.
* Implementing references. * adding copilot cli to dev container. * adjust names after refactor. * Adding operation and template parameters. * Added support for template parameter references. * rever extend-expect workaround * format
|
|
||
| export type Optional<T> = T | undefined; | ||
|
|
||
| export function joinPath(...parts: string[]) { |
There was a problem hiding this comment.
You can use pathe for this, there's a dep in core for it already.
| relative?: boolean; | ||
| } | ||
|
|
||
| export function NamespaceName(props: NamespaceNameProps) { |
There was a problem hiding this comment.
Need doc comments on these components.
There was a problem hiding this comment.
This should be marked internal also.
| children: Children; | ||
| } | ||
|
|
||
| export function NamespaceScopeComponent(props: NamespaceScopeProps) { |
| </SourceFile> | ||
| </Output>, | ||
| ).toRenderTo({ | ||
| "main.tsp": d` |
There was a problem hiding this comment.
I think you don't need d when using toRenderTo.
| expect( | ||
| <Output> | ||
| <SourceFile path="main.tsp"> | ||
| <Namespace name="File.Level"> |
There was a problem hiding this comment.
Putting dots in the name isn't good here because it means separate symbols for a namespace named "File.Level" and "Level" (as a member of File). It's just a test but good to note that this usage should morally be disallowed.
| <group> | ||
| ( | ||
| {props.parameters && props.parameters.length > 0 && ( | ||
| <Indent nobreak> |
There was a problem hiding this comment.
I think probably you can just use the intrinsic here for a bit more simplicity?
| ( | ||
| {props.parameters && props.parameters.length > 0 && ( | ||
| <Indent nobreak> | ||
| <For each={props.parameters} joiner={", "}> |
There was a problem hiding this comment.
use comma softline instead of this joiner and you'll get better formatting when operations are too long (add test to validate this) and won't need the softline within the block.
|
|
||
| export function Reference(props: ReferenceProps) { | ||
| const { refkey } = props; | ||
| const symbol = ref(refkey); |
There was a problem hiding this comment.
Probably should make ref just return a ref (strong regrets on this naming convention lol)
| const usings = computed(() => scope.usings); | ||
| return ( | ||
| <CoreSourceFile path={props.path} filetype="typespec"> | ||
| <List joiner={<hbr />} ender={<hbr />}> |
| import { SourceFileScope } from "../scopes/source-file.js"; | ||
| import { NamespaceSymbol } from "../symbols/index.js"; | ||
|
|
||
| export function createGlobalNamespace(parent: SourceFileScope | ProgramScope) { |
There was a problem hiding this comment.
I think we can eliminate the notion of "program scope", global namespace is a typespec concept and should be sufficient here?
This pull request introduces a suite of new TypeSpec component implementations and comprehensive tests for namespace, operation, name, and reference handling. It also improves developer tooling and workflow with formatting and devcontainer enhancements. The most important changes are grouped below:
New Component Implementations
src/components/. These enable structured rendering and context propagation for TypeSpec constructs. [1] [2] [3] [4] [5]Namecomponent for rendering declaration names with context validation.Referencecomponent for resolving and rendering type references, including proper symbol emission and fallback for unresolved references.Comprehensive Test Coverage
Namespace,OperationDeclaration,Name, andReferencecomponents to verify correct rendering, context handling, error cases, and reference resolution across files and directories. [1] [2] [3] [4]Developer Tooling & Workflow
formatscript using Prettier topackage.jsonfor consistent code formatting.