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

[Not Ready] [typespec-vscode] Improvements for the intellisense of tspconfig.yaml #5186

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b0ac596
Merge pull request #1 from microsoft/main
mzhongl524 Nov 22, 2024
3fcbe52
Merge branch 'microsoft:main' into main
mzhongl524 Nov 25, 2024
881e4b6
Add a intellisense for the extends path in tspconfig.yaml
mzhongl524 Nov 25, 2024
dd4314b
fix warning
mzhongl524 Nov 25, 2024
a43f7e9
Some autocompletes in linters, extends autocomplete updates
mzhongl524 Nov 26, 2024
47e65f8
fix emitter option auto complete while inside "" will add extra ""
mzhongl524 Nov 27, 2024
18025cc
fix emitter option auto complete debug; revert vscode side code
mzhongl524 Nov 28, 2024
51084bc
linter complete rule
mzhongl524 Dec 2, 2024
7344ef2
extends autocomplete
mzhongl524 Dec 2, 2024
82f2ac7
imports autocomplete
mzhongl524 Dec 2, 2024
81df10c
add more info to distinguish required or optional parameter for emitt…
mzhongl524 Dec 3, 2024
da93740
completion for known variables/parameters/env interpolation
mzhongl524 Dec 4, 2024
54726b8
update extends/imports path autocompletion and required or optional p…
mzhongl524 Dec 5, 2024
759ec59
update linter rules/ruleSets
mzhongl524 Dec 5, 2024
6f249c7
Partially updated
mzhongl524 Dec 9, 2024
849973b
Update variable interpolation
mzhongl524 Dec 9, 2024
9d30083
updated
mzhongl524 Dec 11, 2024
3780210
updated and add test
mzhongl524 Dec 16, 2024
bfb5b14
updated
mzhongl524 Dec 17, 2024
92a2540
updated and add some testing
mzhongl524 Dec 19, 2024
5b8eba7
Create improvements-for-the-intellisense-of-tspconfig.yaml-2024-11-19…
mzhongl524 Dec 19, 2024
facf5e5
update code and change logs
mzhongl524 Dec 23, 2024
3bf6351
Update improvements-for-the-intellisense-of-tspconfig.yaml-2024-11-19…
mzhongl524 Dec 24, 2024
26e1f3e
updated
mzhongl524 Dec 24, 2024
73eea1f
Merge branch 'improvements-for-the-intellisense-of-tspconfig.yaml' of…
mzhongl524 Dec 24, 2024
81c3ced
updated
mzhongl524 Dec 24, 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,10 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Improvements for the intellisense of tspconfig.yaml
- Support the auto completion for extends, imports, rule, rule sets and variables in tspconfig.yaml
- Show required/optional information in the details of emitter's options completion item in tspconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Fix bug in tspconfig.yaml
- Fix the issue that emitter option auto complete while inside "" will add extra ""`
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the issue that extra " will be added when auto completing emitter options inside ""

Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
import { joinPaths } from "../core/path-utils.js";
import { NpmPackage, NpmPackageProvider } from "./npm-package-provider.js";

export class EmitterProvider {
private isEmitterPackageCache = new Map<string, boolean>();
constructor(private npmPackageProvider: NpmPackageProvider) {}
export class LibraryProvider {
private libPackageFilterResultCache = new Map<string, boolean>();
constructor(
private npmPackageProvider: NpmPackageProvider,
private filter: (libExports: Record<string, any>) => boolean,
) {}

/**
*
* @param startFolder folder starts to search for package.json with emitters defined as dependencies
* @param startFolder folder starts to search for package.json with library defined as dependencies
* @returns
*/
async listEmitters(startFolder: string): Promise<Record<string, NpmPackage>> {
async listLibraries(startFolder: string): Promise<Record<string, NpmPackage>> {
const packageJsonFolder = await this.npmPackageProvider.getPackageJsonFolder(startFolder);
if (!packageJsonFolder) return {};

const pkg = await this.npmPackageProvider.get(packageJsonFolder);
const data = await pkg?.getPackageJsonData();
if (!data) return {};

const emitters: Record<string, NpmPackage> = {};
const libs: Record<string, NpmPackage> = {};
const allDep = {
...(data.dependencies ?? {}),
...(data.devDependencies ?? {}),
};
for (const dep of Object.keys(allDep)) {
const depPkg = await this.getEmitterFromDep(packageJsonFolder, dep);
const depPkg = await this.getLibraryFromDep(packageJsonFolder, dep);
if (depPkg) {
emitters[dep] = depPkg;
libs[dep] = depPkg;
}
}
return emitters;
return libs;
}

/**
*
* @param startFolder folder starts to search for package.json with emitters defined as dependencies
* @param emitterName
* @param startFolder folder starts to search for package.json with library defined as dependencies
* @param libName
* @returns
*/
async getEmitter(startFolder: string, emitterName: string): Promise<NpmPackage | undefined> {
async getLibrary(startFolder: string, libName: string): Promise<NpmPackage | undefined> {
const packageJsonFolder = await this.npmPackageProvider.getPackageJsonFolder(startFolder);
if (!packageJsonFolder) {
return undefined;
}
return this.getEmitterFromDep(packageJsonFolder, emitterName);
return this.getLibraryFromDep(packageJsonFolder, libName);
}

private async isEmitter(depName: string, pkg: NpmPackage) {
if (this.isEmitterPackageCache.has(depName)) {
return this.isEmitterPackageCache.get(depName);
private async getLibFilterResult(depName: string, pkg: NpmPackage) {
if (this.libPackageFilterResultCache.has(depName)) {
return this.libPackageFilterResultCache.get(depName);
}

const data = await pkg.getPackageJsonData();
Expand All @@ -61,19 +64,20 @@ export class EmitterProvider {
const exports = await pkg.getModuleExports();
// don't add to cache when failing to load exports which is unexpected
if (!exports) return false;
const isEmitter = exports.$onEmit !== undefined;
this.isEmitterPackageCache.set(depName, isEmitter);
return isEmitter;

const filterResult = this.filter(exports);
this.libPackageFilterResultCache.set(depName, filterResult);
return filterResult;
} else {
this.isEmitterPackageCache.set(depName, false);
this.libPackageFilterResultCache.set(depName, false);
return false;
}
}

private async getEmitterFromDep(packageJsonFolder: string, depName: string) {
private async getLibraryFromDep(packageJsonFolder: string, depName: string) {
const depFolder = joinPaths(packageJsonFolder, "node_modules", depName);
const depPkg = await this.npmPackageProvider.get(depFolder);
if (depPkg && (await this.isEmitter(depName, depPkg))) {
if (depPkg && (await this.getLibFilterResult(depName, depPkg))) {
return depPkg;
}
return undefined;
Expand Down
13 changes: 11 additions & 2 deletions packages/compiler/src/server/serverlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ import { createCompileService } from "./compile-service.js";
import { resolveCompletion } from "./completion.js";
import { Commands } from "./constants.js";
import { convertDiagnosticToLsp } from "./diagnostics.js";
import { EmitterProvider } from "./emitter-provider.js";
import { createFileService } from "./file-service.js";
import { createFileSystemCache } from "./file-system-cache.js";
import { LibraryProvider } from "./lib-provider.js";
import { NpmPackageProvider } from "./npm-package-provider.js";
import { getSymbolStructure } from "./symbol-structure.js";
import { provideTspconfigCompletionItems } from "./tspconfig/completion.js";
Expand Down Expand Up @@ -114,7 +114,14 @@ export function createServer(host: ServerHost): Server {
});
const compilerHost = createCompilerHost();
const npmPackageProvider = new NpmPackageProvider(compilerHost);
const emitterProvider = new EmitterProvider(npmPackageProvider);
const emitterProvider = new LibraryProvider(
npmPackageProvider,
(exports) => exports.$onEmit !== undefined,
);
const linterProvider = new LibraryProvider(
npmPackageProvider,
(exports) => exports.$linter !== undefined,
);

const compileService = createCompileService({
fileService,
Expand Down Expand Up @@ -703,7 +710,9 @@ export function createServer(host: ServerHost): Server {
if (doc) {
const items = await provideTspconfigCompletionItems(doc, params.position, {
fileService,
compilerHost,
emitterProvider,
linterProvider,
log,
});
return CompletionList.create(items);
Expand Down
Loading
Loading