Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support completion for tspconfig.yaml file in vscode #4790

Merged
merged 38 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b09a0d4
support load packages with cache
RodgeFu Sep 23, 2024
95b5b14
Merge remote-tracking branch 'upstream/main' into tspconfig-auto-comp…
RodgeFu Sep 24, 2024
ed1c6a7
support tspconfig.yaml auto-complete
RodgeFu Sep 27, 2024
83ae96d
Merge remote-tracking branch 'upstream/main' into tspconfig-auto-comp…
RodgeFu Sep 27, 2024
5b17b89
some refactor
RodgeFu Sep 27, 2024
d1577cd
add unit test and some refine
RodgeFu Oct 9, 2024
90e1eee
Merge remote-tracking branch 'upstream/main' into tspconfig-auto-comp…
RodgeFu Oct 9, 2024
c6b1ddc
add test for tspconfig auto complete
RodgeFu Oct 10, 2024
a051b7a
some refine in code
RodgeFu Oct 11, 2024
c39038e
refine code
RodgeFu Oct 11, 2024
0966eda
fix some issues
RodgeFu Oct 16, 2024
c3d898b
fix mapping file
RodgeFu Oct 16, 2024
b8dfd5d
small refine
RodgeFu Oct 17, 2024
349d83d
some more update
RodgeFu Oct 18, 2024
fe026be
update to watch folder instead of file to get add/delete event
RodgeFu Oct 18, 2024
7a647f8
add changelog
RodgeFu Oct 18, 2024
b013f6c
Merge remote-tracking branch 'upstream/main' into tspconfig-auto-comp…
RodgeFu Oct 18, 2024
39df8ff
add some comment
RodgeFu Oct 18, 2024
3d56196
update changelog
RodgeFu Oct 18, 2024
3ab3733
add changelog
RodgeFu Oct 18, 2024
1856276
add changelog
RodgeFu Oct 18, 2024
8e885f9
move completion of tspconfig to compiler
RodgeFu Oct 23, 2024
a385854
some small update
RodgeFu Oct 23, 2024
f03be39
merge from upstream/main
RodgeFu Oct 23, 2024
85accbc
update pnpm-lock
RodgeFu Oct 23, 2024
bbd87b3
update watch func in host
RodgeFu Oct 23, 2024
295074b
Merge branch 'main' into tspconfig-auto-complete
RodgeFu Oct 23, 2024
e8e4b65
update pnpm lock
RodgeFu Oct 23, 2024
1ea469b
update for prettier warning
RodgeFu Oct 23, 2024
d47f262
fix watch's close impl
RodgeFu Oct 23, 2024
3bced9b
update per comment
RodgeFu Oct 24, 2024
424a86c
revert unexpected change
RodgeFu Oct 24, 2024
a49ba7c
add changelog for compiler watch
RodgeFu Oct 24, 2024
8f7be84
update per prettier comment
RodgeFu Oct 24, 2024
ef41b8b
Merge remote-tracking branch 'upstream/main' into tspconfig-auto-comp…
RodgeFu Oct 24, 2024
57c33b9
remove .orig file
RodgeFu Oct 24, 2024
034ae29
remove watch from compilerhost
RodgeFu Oct 29, 2024
54f1739
some update
RodgeFu Oct 29, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
- typespec-vscode
---

Support completion for tspconfig.yaml file in vscode
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/internal-build-utils"
---

Fix bug: skip package.json whose name is undefined
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
"order": 2
}
},
{
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
"type": "node",
"request": "launch",
"name": "Generate-third-party-notices for vscode extension",
"program": "${workspaceFolder}/packages/internal-build-utils/dist/src/cli.js",
"args": ["generate-third-party-notices"],
"sourceMaps": true,
"skipFiles": ["<node_internals>/**/*.js"],
"cwd": "${workspaceFolder}/packages/typespec-vscode"
},
{
"name": "Regenerate .tmlanguage",
"type": "node",
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/config/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const TypeSpecConfigJsonSchema: JSONSchemaType<TypeSpecRawConfig> = {
emitters: {
type: "object",
nullable: true,
deprecated: true,
required: [],
additionalProperties: {
oneOf: [{ type: "boolean" }, emitterOptionsSchema],
Expand Down
6 changes: 5 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 { Server, ServerHost, ServerLog, ServerOnRequestMethodName } from "./types.js";

let server: Server | undefined = undefined;

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

const getTypespecConfigJsonSchemaMethodName: ServerOnRequestMethodName =
"typespec/getTypeSpecConfigJsonSchema";
connection.onRequest(getTypespecConfigJsonSchemaMethodName, s.getTypeSpecConfigJsonSchema);

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

Expand Down
8 changes: 8 additions & 0 deletions packages/compiler/src/server/serverlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
WorkspaceEdit,
WorkspaceFoldersChangeEvent,
} from "vscode-languageserver/node.js";
import { TypeSpecConfigJsonSchema } from "../config/config-schema.js";
import { TypeSpecRawConfig } from "../config/types.js";
import { CharCode } from "../core/charcode.js";
import { resolveCodeFix } from "../core/code-fixes.js";
import { compilerAssert, getSourceLocation } from "../core/diagnostics.js";
Expand All @@ -66,6 +68,7 @@ import {
Diagnostic,
DiagnosticTarget,
IdentifierNode,
JSONSchemaType,
Node,
PositionDetail,
SourceFile,
Expand Down Expand Up @@ -155,6 +158,7 @@ export function createServer(host: ServerHost): Server {
getCodeActions,
executeCommand,
log,
getTypeSpecConfigJsonSchema,
};

async function initialize(params: InitializeParams): Promise<InitializeResult> {
Expand Down Expand Up @@ -247,6 +251,10 @@ export function createServer(host: ServerHost): Server {
log({ level: "info", message: "Initialization complete." });
}

async function getTypeSpecConfigJsonSchema(): Promise<JSONSchemaType<TypeSpecRawConfig>> {
return TypeSpecConfigJsonSchema;
}

async function workspaceFoldersChanged(e: WorkspaceFoldersChangeEvent) {
log({ level: "info", message: "Workspace Folders Changed", detail: e });
const map = new Map(workspaceFolders.map((f) => [f.uri, f]));
Expand Down
13 changes: 12 additions & 1 deletion packages/compiler/src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ import {
WorkspaceFoldersChangeEvent,
} from "vscode-languageserver";
import { TextDocument, TextEdit } from "vscode-languageserver-textdocument";
import type { CompilerHost, Program, SourceFile, TypeSpecScriptNode } from "../core/index.js";
import { TypeSpecRawConfig } from "../config/types.js";
import type {
CompilerHost,
JSONSchemaType,
Program,
SourceFile,
TypeSpecScriptNode,
} from "../core/index.js";

export type ServerLogLevel = "trace" | "debug" | "info" | "warning" | "error";
export interface ServerLog {
Expand Down Expand Up @@ -89,8 +96,12 @@ export interface Server {
getCodeActions(params: CodeActionParams): Promise<CodeAction[]>;
executeCommand(params: ExecuteCommandParams): Promise<void>;
log(log: ServerLog): void;
// following methods are going through onRequest interface of LSP
getTypeSpecConfigJsonSchema(): Promise<JSONSchemaType<TypeSpecRawConfig>>;
}

export type ServerOnRequestMethodName = "typespec/getTypeSpecConfigJsonSchema";

export interface ServerSourceFile extends SourceFile {
// Keep track of the open document (if any) associated with a source file.
readonly document?: TextDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ async function getPackageRoot(filename: string): Promise<string | undefined> {
try {
const pkgPath = join(dir, "package.json");
await stat(pkgPath);
const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
if (!pkg.name) {
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
return getPackageRoot(dir);
}
return dir;
} catch (e: any) {
if (e.code === "ENOENT") {
Expand Down
23 changes: 22 additions & 1 deletion packages/typespec-vscode/ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ granted herein, whether by implication, estoppel or otherwise.
2. brace-expansion version 2.0.1 (https://github.com/juliangruber/brace-expansion)
3. minimatch version 5.1.6 (https://github.com/isaacs/minimatch)
4. semver version 7.6.3 (https://github.com/npm/node-semver)
5. yaml version 2.5.1 (github:eemeli/yaml)


%% balanced-match NOTICES AND INFORMATION BEGIN HERE
Expand Down Expand Up @@ -111,4 +112,24 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

=====================================================");
END OF semver NOTICES AND INFORMATION
END OF semver NOTICES AND INFORMATION


%% yaml NOTICES AND INFORMATION BEGIN HERE
=====================================================
Copyright Eemeli Aro <eemeli@gmail.com>

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

=====================================================");
END OF yaml NOTICES AND INFORMATION
10 changes: 7 additions & 3 deletions packages/typespec-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
},
"activationEvents": [
"onLanguage:typespec",
"onCommand:typespec.restartServer"
"onCommand:typespec.restartServer",
"workspaceContains:**/tspconfig.yaml"
],
"icon": "./icons/logo.png",
"contributes": {
Expand Down Expand Up @@ -155,8 +156,10 @@
"package-vsix": "vsce package",
"deploy": "vsce publish",
"open-in-browser": "vscode-test-web --extensionDevelopmentPath=. .",
"test": "vitest run",
"test:watch": "vitest -w",
"test:e2e": "pnpm test:web",
"test:web": "vscode-test-web --extensionDevelopmentPath=. --headless --extensionTestsPath=dist/test/suite.js ./test/data"
"test:web": "vscode-test-web --extensionDevelopmentPath=. --headless --extensionTestsPath=dist/test/web/suite.js ./test/web/data"
},
"devDependencies": {
"@rollup/plugin-commonjs": "~28.0.0",
Expand All @@ -177,6 +180,7 @@
"rollup": "~4.24.0",
"typescript": "~5.6.3",
"vitest": "^2.1.2",
"vscode-languageclient": "~9.0.1"
"vscode-languageclient": "~9.0.1",
"vscode-languageserver-textdocument": "~1.0.12"
}
}
20 changes: 16 additions & 4 deletions packages/typespec-vscode/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import path from "path";

import { defineConfig } from "rollup";
import { fileURLToPath } from "url";

const curFile = fileURLToPath(import.meta.url);
const curDir = path.dirname(curFile);

const plugins = [(resolve as any)({ preferBuiltins: true }), (commonjs as any)()];
const baseConfig = defineConfig({
Expand Down Expand Up @@ -53,17 +58,24 @@ export default defineConfig([
},
{
...baseConfig,
input: "test/suite.ts",
input: "test/web/suite.ts",
output: {
file: "dist/test/suite.js", // VSCode web will add extra .js if you use .cjs
file: "dist/test/web/suite.js", // VSCode web will add extra .js if you use .cjs
format: "commonjs",
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [...plugins, ts("dist/test")],
plugins: [...plugins, ts("dist/test/web")],
},
]);

function ts(outDir: string) {
return (typescript as any)({ tsconfig: "./tsconfig.build.json", outDir });
return (typescript as any)({
compilerOptions: {
// set sourceRoot to absolute path, otherwise the path in the map file generated is incorrect when outDir is given
sourceRoot: curDir,
},
tsconfig: "./tsconfig.build.json",
outDir,
});
}
88 changes: 0 additions & 88 deletions packages/typespec-vscode/src/extension-logger.ts

This file was deleted.

Loading
Loading