forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support scaffolding scenario in vscode (microsoft#5294)
Support scaffolding scenario in vscode whose user experience is like "tsp init". Vscode would collect information from end user and work with compiler to create new TypeSpec project underneath. fixes: microsoft#4859
- Loading branch information
Showing
25 changed files
with
2,229 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- typespec-vscode | ||
--- | ||
|
||
Support "Create TypeSpec Project" in vscode command and EXPLORER when no folder opened | ||
Add Setting "typespec.initTemplatesUrls" where user can configure additional template to use to create TypeSpec project | ||
example: | ||
``` | ||
{ | ||
"typespec.initTemplatesUrls": [ | ||
{ | ||
"name": "displayName", | ||
"url": "https://urlToTheFileContainsTemplates" | ||
}], | ||
} | ||
``` | ||
Support "Install TypeSpec Compiler/CLI globally" in vscode command to install TypeSpec compiler globally easily | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: feature | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Add capacities in TypeSpec Language Server to support "Scaffolding new TypeSpec project" in IDE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const NodeHost = undefined; | ||
export const CompilerPackageRoot = undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import { readFile } from "fs/promises"; | ||
import { CompilerPackageRoot } from "../core/node-host.js"; | ||
import { resolvePath } from "../core/path-utils.js"; | ||
import { CompilerHost } from "../index.js"; | ||
|
||
export const templatesDir = resolvePath(CompilerPackageRoot, "templates"); | ||
export interface LoadedCoreTemplates { | ||
readonly baseUri: string; | ||
readonly templates: Record<string, any>; | ||
} | ||
|
||
const content = JSON.parse(await readFile(resolvePath(templatesDir, "scaffolding.json"), "utf-8")); | ||
|
||
export const TypeSpecCoreTemplates = { | ||
baseUri: templatesDir, | ||
templates: content, | ||
}; | ||
let typeSpecCoreTemplates: LoadedCoreTemplates | undefined; | ||
export async function getTypeSpecCoreTemplates(host: CompilerHost): Promise<LoadedCoreTemplates> { | ||
if (typeSpecCoreTemplates === undefined) { | ||
const file = await host.readFile(resolvePath(templatesDir, "scaffolding.json")); | ||
const content = JSON.parse(file.text); | ||
typeSpecCoreTemplates = { | ||
baseUri: templatesDir, | ||
templates: content, | ||
}; | ||
} | ||
return typeSpecCoreTemplates; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createJSONSchemaValidator } from "../core/schema-validator.js"; | ||
import { Diagnostic, NoTarget, SourceFile } from "../index.js"; | ||
import { InitTemplateSchema } from "./init-template.js"; | ||
|
||
export type ValidationResult = { | ||
valid: boolean; | ||
diagnostics: readonly Diagnostic[]; | ||
}; | ||
|
||
export function validateTemplateDefinitions( | ||
template: unknown, | ||
templateName: SourceFile | typeof NoTarget, | ||
strictValidation: boolean, | ||
): ValidationResult { | ||
const validator = createJSONSchemaValidator(InitTemplateSchema, { | ||
strict: strictValidation, | ||
}); | ||
const diagnostics = validator.validate(template, templateName); | ||
return { valid: diagnostics.length === 0, diagnostics }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.