Skip to content

Commit

Permalink
Merge branch 'main' into void-body-with-model-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChen-us authored Dec 19, 2024
2 parents 0152f3a + 7dc64d8 commit 8299f58
Show file tree
Hide file tree
Showing 211 changed files with 7,364 additions and 3,239 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/tadelesh-patch-1-2024-11-18-16-37-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-specs"
---

fix missing `@list` decorator for unbranded pageable operation
7 changes: 7 additions & 0 deletions .chronus/changes/vs-vulnerabilities-2024-11-12-13-19-40.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- typespec-vs
---

Upgrade nuget packages to avoid transitive vulnerabilities
20 changes: 20 additions & 0 deletions .chronus/changes/vscode-scaffolding-2024-11-7-12-44-28.md
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

7 changes: 7 additions & 0 deletions .chronus/changes/vscode-scaffolding-2024-11-7-12-46-5.md
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
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ words:
- itor
- ivar
- Jacoco
- javac
- jdwp
- jobject
- Johan
Expand Down
4 changes: 2 additions & 2 deletions eng/emitters/pipelines/templates/steps/test-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ steps:
displayName: "Upload Cadl Ranch Standard Coverage Report"
condition: and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'internal'), eq('${{ parameters.EmitArtifacts }}', true))
inputs:
azureSubscription: "Cadl Ranch Storage"
azureSubscription: "TypeSpec Storage"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: npx cadl-ranch upload-coverage --coverageFile ./generator/artifacts/coverage/cadl-ranch-coverage-${{ parameters.LanguageShortName }}-standard.json --generatorName ${{ coalesce(parameters.CadlRanchName, parameters.LanguageShortName) }} --storageAccountName azuresdkcadlranch --generatorVersion $(node -p -e "require('./package.json').version") --generatorMode standard
inlineScript: npx tsp-spector upload-coverage --coverageFile ./generator/artifacts/coverage/tsp-spector-coverage-${{ parameters.LanguageShortName }}-standard.json --generatorName ${{ coalesce(parameters.CadlRanchName, parameters.LanguageShortName) }} --storageAccountName typespec --generatorVersion $(node -p -e "require('./package.json').version") --generatorMode standard
workingDirectory: $(selfRepositoryPath)${{ parameters.PackagePath }}
44 changes: 44 additions & 0 deletions eng/tsp-core/pipelines/dashboard-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
trigger:
branches:
include:
- main
# For patch releases
- release/*

pr: none

extends:
template: /eng/common/pipelines/templates/1es-redirect.yml
parameters:
variables:
- template: /eng/tsp-core/pipelines/templates/variables/globals.yml@self

stages:
- stage: build
displayName: Build and Deploy

pool:
name: $(WINDOWSPOOL)
image: $(WINDOWSVMIMAGE)
os: windows

jobs:
- job: build
displayName: Build

variables:
TYPESPEC_SKIP_DOCUSAURUS_BUILD: true # Disable docusaurus build

steps:
- template: /eng/tsp-core/pipelines/templates/install.yml
- template: /eng/tsp-core/pipelines/templates/build.yml

- task: AzureCLI@2
inputs:
azureSubscription: "TypeSpec Storage"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: |
echo "Uploading files to Azure Blob Storage..."
az storage blob upload-batch --account-name specdashboard --source packages/spec-dashboard/dist/ --destination '$web' --overwrite
displayName: "Upload files to Azure Blob Storage"
26 changes: 26 additions & 0 deletions eng/tsp-core/pipelines/pr-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,37 @@ extends:
--destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \
--source "./website/dist/" \
--overwrite
- task: CopyFiles@2
displayName: "Copy VSCode extension .vsix to artifact directory"
inputs:
SourceFolder: "$(Build.SourcesDirectory)/packages/typespec-vscode"
Contents: "*.vsix"
TargetFolder: "$(Build.ArtifactStagingDirectory)/vscode-extension"
templateContext:
outputs:
- output: pipelineArtifact
path: $(Build.ArtifactStagingDirectory)/vscode-extension
artifact: vscode-extension
displayName: Copy VSCode extension .vsix to artifact directory
- job: tryit_comment
displayName: Create TryIt comment
dependsOn: tryit
steps:
- pwsh: |
$curlCommand = 'curl -s -u :$(System.AccessToken) "$(System.TeamFoundationCollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/artifacts?artifactName=vscode-extension"'
$response = Invoke-Expression $curlCommand
$responseObject = $response | ConvertFrom-Json
Write-Host "response: $response"
$downloadUrl = $responseObject.resource.downloadUrl
Write-Output "Artifact URL: $downloadUrl"
Write-Host "##vso[task.setvariable variable=vscodeUrl]$downloadUrl"
displayName: Get vscode artifact URL
- script: npx tsx eng/tsp-core/scripts/create-tryit-comment.ts
displayName: Check already commented
env:
GH_TOKEN: $(azuresdk-github-pat)
VSCODE_DOWNLOAD_URL: $(vscodeUrl)

- job: change_comment
displayName: Describe changes on PR
Expand Down
12 changes: 10 additions & 2 deletions eng/tsp-core/scripts/create-tryit-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function main() {
const repo = process.env["BUILD_REPOSITORY_ID"];
const prNumber = process.env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"];
const ghToken = process.env.GH_TOKEN;
const vscodeDownloadUrl = process.env.VSCODE_DOWNLOAD_URL;
if (repo === undefined) {
throw new Error("BUILD_REPOSITORY_ID environment variable is not set");
}
Expand All @@ -33,17 +34,24 @@ async function main() {
return;
}

const comment = makeComment(folderName, prNumber);
const comment = makeComment(folderName, prNumber, vscodeDownloadUrl);
await writeComment(repo, prNumber, comment, ghAuth);
}

function makeComment(folderName: string, prNumber: string): string {
function makeComment(
folderName: string,
prNumber: string,
vscodeDownloadUrl: string | undefined,
): string {
const links = [
`[🛝 Playground]( https://cadlplayground.z22.web.core.windows.net${folderName}/prs/${prNumber}/)`,
`[🌐 Website](https://tspwebsitepr.z22.web.core.windows.net${folderName}/prs/${prNumber}/)`,
`[📚 Next docs](https://tspwebsitepr.z22.web.core.windows.net${folderName}/prs/${prNumber}/docs/next.html)`,
];

if (vscodeDownloadUrl) {
links.push(`[🛝 VSCode Extension]( ${vscodeDownloadUrl})`);
}
return [
`<!-- ${TRY_ID_COMMENT_IDENTIFIER} -->`,
`You can try these changes here`,
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/core/node-host.browser.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const NodeHost = undefined;
export const CompilerPackageRoot = undefined;
24 changes: 17 additions & 7 deletions packages/compiler/src/init/core-templates.ts
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;
}
20 changes: 20 additions & 0 deletions packages/compiler/src/init/init-template-validate.ts
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 };
}
28 changes: 6 additions & 22 deletions packages/compiler/src/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import prompts from "prompts";
import * as semver from "semver";
import { createDiagnostic } from "../core/messages.js";
import { getBaseFileName, getDirectoryPath } from "../core/path-utils.js";
import { createJSONSchemaValidator } from "../core/schema-validator.js";
import { CompilerHost, Diagnostic, NoTarget, SourceFile } from "../core/types.js";
import { MANIFEST } from "../manifest.js";
import { readUrlOrPath } from "../utils/misc.js";
import { TypeSpecCoreTemplates } from "./core-templates.js";
import { InitTemplate, InitTemplateLibrarySpec, InitTemplateSchema } from "./init-template.js";
import { getTypeSpecCoreTemplates } from "./core-templates.js";
import { validateTemplateDefinitions, ValidationResult } from "./init-template-validate.js";
import { InitTemplate, InitTemplateLibrarySpec } from "./init-template.js";
import { makeScaffoldingConfig, normalizeLibrary, scaffoldNewProject } from "./scaffold.js";

export interface InitTypeSpecProjectOptions {
Expand All @@ -30,15 +30,16 @@ export async function initTypeSpecProject(

// Download template configuration and prompt user to select a template
// No validation is done until one has been selected
const typeSpecCoreTemplates = await getTypeSpecCoreTemplates(host);
const result =
options.templatesUrl === undefined
? (TypeSpecCoreTemplates as LoadedTemplate)
? (typeSpecCoreTemplates as LoadedTemplate)
: await downloadTemplates(host, options.templatesUrl);
const templateName = options.template ?? (await promptTemplateSelection(result.templates));

// Validate minimum compiler version for non built-in templates
if (
result !== TypeSpecCoreTemplates &&
result !== typeSpecCoreTemplates &&
!(await validateTemplate(result.templates[templateName], result))
) {
return;
Expand Down Expand Up @@ -193,11 +194,6 @@ async function promptTemplateSelection(templates: Record<string, any>): Promise<
return templateName;
}

type ValidationResult = {
valid: boolean;
diagnostics: readonly Diagnostic[];
};

async function validateTemplate(template: any, loaded: LoadedTemplate): Promise<boolean> {
// After selection, validate the template definition
const currentCompilerVersion = MANIFEST.version;
Expand Down Expand Up @@ -278,18 +274,6 @@ export class InitTemplateError extends Error {
}
}

function validateTemplateDefinitions(
template: unknown,
templateName: SourceFile,
strictValidation: boolean,
): ValidationResult {
const validator = createJSONSchemaValidator(InitTemplateSchema, {
strict: strictValidation,
});
const diagnostics = validator.validate(template, templateName);
return { valid: diagnostics.length === 0, diagnostics };
}

function logDiagnostics(diagnostics: readonly Diagnostic[]): void {
diagnostics.forEach((diagnostic) => {
// eslint-disable-next-line no-console
Expand Down
9 changes: 8 additions & 1 deletion packages/compiler/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { NodeHost } from "../core/node-host.js";
import { typespecVersion } from "../utils/misc.js";
import { createServer } from "./serverlib.js";
import { Server, ServerHost, ServerLog } from "./types.js";
import { CustomRequestName, Server, ServerHost, ServerLog } from "./types.js";

let server: Server | undefined = undefined;

Expand Down Expand Up @@ -129,6 +129,13 @@ function main() {
connection.onExecuteCommand(profile(s.executeCommand));
connection.languages.semanticTokens.on(profile(s.buildSemanticTokens));

const validateInitProjectTemplate: CustomRequestName = "typespec/validateInitProjectTemplate";
connection.onRequest(validateInitProjectTemplate, profile(s.validateInitProjectTemplate));
const getInitProjectContextRequestName: CustomRequestName = "typespec/getInitProjectContext";
connection.onRequest(getInitProjectContextRequestName, profile(s.getInitProjectContext));
const initProjectRequestName: CustomRequestName = "typespec/initProject";
connection.onRequest(initProjectRequestName, profile(s.initProject));

documents.onDidChangeContent(profile(s.checkChange));
documents.onDidClose(profile(s.documentClosed));

Expand Down
Loading

0 comments on commit 8299f58

Please sign in to comment.