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

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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 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
82faddf
updated test
mzhongl524 Dec 27, 2024
09b8796
test update for pipeline
mzhongl524 Dec 30, 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
71 changes: 71 additions & 0 deletions packages/typespec-vscode/src/completion-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as fs from "fs";
import * as path from "path";
import vscode from "vscode";

export function createExtendsCompletionItemProvider() {
return vscode.languages.registerCompletionItemProvider(
"yaml",
{
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
// get all text until the `position` and check if it reads `extends:.`
// and if so then complete if `log`, `warn`, and `error`
const linePrefix = document.lineAt(position).text.slice(0, position.character);
const result: vscode.CompletionItem[] = [];

if (linePrefix.includes("extends:")) {
const curActiveFile = vscode.window.activeTextEditor?.document.fileName;
if (!curActiveFile) {
return result;
}

if (vscode.workspace.workspaceFolders) {
const pos = curActiveFile.lastIndexOf("\\");
const fileName = curActiveFile.slice(pos + 1, curActiveFile.length);
const yamlFiles = findFilesWithSameExtension(
vscode.workspace.workspaceFolders[0].uri.fsPath,
fileName,
);

yamlFiles.forEach((file) => {
result.push({
label: file,
kind: vscode.CompletionItemKind.Value,
});
});
}
}
return result;
},
},
":",
);
}

function findFilesWithSameExtension(rootPath: string, fileName: string): string[] {
const fileExtension = path.extname(fileName);
const result: string[] = [];
const exclude = [".vs", ".vscode", "tsp-output", "node_modules", ".gitignore", "main.tsp"];

function searchDirectory(currentDir: string) {
const files = fs.readdirSync(currentDir);

for (const file of files) {
if (exclude.includes(file)) {
continue;
}

const fullPath = path.join(currentDir, file);
const stat = fs.statSync(fullPath);

if (stat.isDirectory()) {
searchDirectory(fullPath);
} else if (file !== fileName && path.extname(file) === fileExtension) {
const newRelativePath = path.relative(rootPath, fullPath);
result.push(" ./" + newRelativePath.replace("\\", "/"));
Fixed Show fixed Hide fixed
}
}
}

searchDirectory(rootPath);
return result;
}
3 changes: 3 additions & 0 deletions packages/typespec-vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import vscode, { commands, ExtensionContext } from "vscode";
import { createExtendsCompletionItemProvider } from "./completion-provider.js";
import { SettingName } from "./const.js";
import { ExtensionLogListener } from "./log/extension-log-listener.js";
import logger from "./log/logger.js";
Expand All @@ -17,6 +18,8 @@ logger.registerLogListener("extension-log", new ExtensionLogListener(outputChann
export async function activate(context: ExtensionContext) {
context.subscriptions.push(createTaskProvider());

context.subscriptions.push(createExtendsCompletionItemProvider());

context.subscriptions.push(
commands.registerCommand("typespec.showOutputChannel", () => {
outputChannel.show(true /*preserveFocus*/);
Expand Down
Loading