Skip to content

Commit

Permalink
Feature: Update kiota vs code extension (#4500)
Browse files Browse the repository at this point in the history
* add tree view

* add Api files conatiner and remove previous containers

* rename workspace title

* combine search and open description functions

* Add 'close description' button to api title node

* add close description dialog

* add generate option step

* added plugin dialog steps

* added icon toggling

* add workspace.json file to workspace

* Fix some server configs

* Ensure the RPC commands use preview features if config is enabled.

* - updates references kiota version for CLI

* - cleans up localization files from unused resource

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* - removes unimplemented command

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* - adds the environment variable passing to the json RPC server

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* - refactors to constant

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* - removes serializers in preview mode

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* - code linting

* - initial plugin generation

Signed-off-by: Vincent Biret <vibiret@microsoft.com>

* Fixed the collection of plugin name

* rename title string

* Add plugin type step

* add generate a manifest type

* close description after generation

* add "Edit Path' button

* add regenerate call

* update file name

* enable editing paths on api explorer

* add regenerate functionality

* - bumps kiota versions to avoid updates which confuses @sebastienlevert and @maisarissi

* - adds FAQ documentation for vs code reinstalling over

* add regeneration button on api explorer

* remove automatic workspace.json file add

* replace string

* update icon

* add plugin re-generation

* add warning notification

* add save notification

* fix delete description appearing on wrong nodes

* remove open file command

* remove output path validation and default to ouptut folder

* move constants to separate file

* remove path autoselection when description is loaded for the first time

* fix workspace.json file not opening

* hide add and remove icon on apiTitle node

* undo closing descriptions after generation

* Adding the automatic sideloading script

* Update to using vsx

* fix icons display

* Merge branch 'main' into elinor/add-kiota-workspace

* remove welcome translations

* remove welcome string translation

* add string translations

* remove unused search lock function

* add french translations

* added czech translations

* add portuguese translations

* update output diectory string

* set workspace file constant

* add else clause

* remove TODO comments

* return vscode error

* add types

* use nullish coalescing operator instead of Logical OR

* add spanish translations

* add italian translation

* add chinese translations

* remove unused functions

* update static strings

* add missing l10n

* update string typo

* update static string localization files

* update french string

* remove else

Co-authored-by: Musale Martin <martinmshale@gmail.com>

* add plugin output selection

* add output directory selection for client generation

* add output directory selection for manifest generation

* add polish translations

* add russian translations

* add swahili translations

* add success message and toggle icons

* add constants

* localize string

* add default and browse output options

* add dropdown for api path selection

* remove unused filter property

* remove else

Co-authored-by: silaskenneth <silaskenneth1@gmail.com>

* update icon

* Fixing vscode sideloading script for Windows

* enable generation from a deeplink

* Updates plugin naming

* update vscode engine

* bump kiota extension version

* Task: Display client/plugin name on API explorer  (#4801)

* hide information messages

* update warning message display

* update regenerate function

* Add constants

* Fix: "Override" message only displays if there's a change on the tree (#4899)

* code clean up

* update plugin type to accept array

* chore: lock update

* chore: bumps version to avoid auto-update

* Fixes unselected paths

* format

* fix regeneration

* API change to migrate lockfile to workspace file

* Adds connections to migrate workspace file

* Fix path maching

* Update vscode/microsoft-kiota/src/openApiTreeProvider.ts

* Fixes plugin generation check

* Fix: Add paste path functionality (#4994)

* Fix: Kiota extension works without a workspace folder open (#4958)

* Fix: Workspace file display (#5029)

* Fix: Display "override" message only when changes have been made (#5048)

* fix typo issue

* fix typecase

* fix cwd update

* chore: bumps extension engine version

* chore: updates lock file

* Feat: Add migration dialog (#5144)

* chore: adds missing french translations

* add missing translations

* simpify function

* rename function

* fix: bumps vscode extension version to allow side-loading

* update message display

* use workspace instead of lock

Co-authored-by: Andrew Omondi <andrueastman@users.noreply.github.com>

* use workspaceFile instead

* format file

* add missing translations

* update function name

* format file

---------

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Co-authored-by: Andrew Omondi <anomondi@microsoft.com>
Co-authored-by: Vincent Biret <vibiret@microsoft.com>
Co-authored-by: Eastman <andrueastman@users.noreply.github.com>
Co-authored-by: Sébastien Levert <slevert@microsoft.com>
Co-authored-by: Musale Martin <martinmshale@gmail.com>
Co-authored-by: silaskenneth <silaskenneth1@gmail.com>
Co-authored-by: Sébastien Levert <sebastienlevert@users.noreply.github.com>
  • Loading branch information
8 people authored Aug 22, 2024
1 parent 651638f commit 9b94384
Show file tree
Hide file tree
Showing 42 changed files with 2,363 additions and 769 deletions.
36 changes: 36 additions & 0 deletions scripts/execute-vscode-sideload.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
param (
[string]
[Parameter(Mandatory = $false)]
$Platform = "win-x64",
[switch]
$WSL
)


Push-Location ./vscode/microsoft-kiota

# Install all dependencies
npm i

# Package the VS Code extension
npx @vscode/vsce package

# Getting package for its version
$PackageJson = Get-Content "package.json" -Raw | ConvertFrom-Json

# Install the extension
code --install-extension "./kiota-$($PackageJson.version).vsix"

$VsCodeRootPath = (Resolve-Path "~/.vscode").Path

if ($WSL) {
$Platform = "linux-x64"
$VsCodeRootPath = (Resolve-Path "~/.vscode-server").Path
}

$KiotaBin = "$VsCodeRootPath/extensions/ms-graph.kiota-$($PackageJson.version)/.kiotabin/$($PackageJson.kiotaVersion)/$Platform"

Pop-Location

# Building Kiota
dotnet publish ./src/kiota/kiota.csproj -p:PublishSingleFile=true -p:PublishReadyToRun=true --self-contained -c Release -r $platform -o $KiotaBin
5 changes: 3 additions & 2 deletions src/kiota/Rpc/IServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ internal interface IServer
Task<SearchOperationResult> SearchAsync(string searchTerm, bool clearCache, CancellationToken cancellationToken);
Task<ShowResult> ShowAsync(string descriptionPath, string[] includeFilters, string[] excludeFilters, bool clearCache, CancellationToken cancellationToken);
Task<ManifestResult> GetManifestDetailsAsync(string manifestPath, string apiIdentifier, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, CancellationToken cancellationToken);
Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, ConsumerOperation operation, CancellationToken cancellationToken);
Task<LanguagesInformation> InfoForDescriptionAsync(string descriptionPath, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, CancellationToken cancellationToken);
Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken);
Task<List<LogEntry>> MigrateFromLockFileAsync(string lockDirectoryPath, CancellationToken cancellationToken);
}
36 changes: 31 additions & 5 deletions src/kiota/Rpc/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Kiota.Builder.Extensions;
using Kiota.Builder.Lock;
using Kiota.Builder.Logging;
using Kiota.Builder.WorkspaceManagement;
using Kiota.Generated;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -137,7 +138,7 @@ private static string NormalizeOperationNodePath(OpenApiUrlTreeNode node, Operat
return indexingNormalizationRegex().Replace(name, "{}");
return name;
}
public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, CancellationToken cancellationToken)
public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, ConsumerOperation operation, CancellationToken cancellationToken)
{
var logger = new ForwardedLogger<KiotaBuilder>();
var configuration = Configuration.Generation;
Expand All @@ -151,7 +152,7 @@ public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string o
configuration.ClearCache = clearCache;
configuration.ExcludeBackwardCompatible = excludeBackwardCompatible;
configuration.IncludeAdditionalData = includeAdditionalData;
configuration.Operation = ConsumerOperation.Add; //TODO should be updated to edit in the edit scenario
configuration.Operation = operation;
if (disabledValidationRules is { Length: > 0 })
configuration.DisabledValidationRules = disabledValidationRules.ToHashSet(StringComparer.OrdinalIgnoreCase);
if (serializers is { Length: > 0 })
Expand Down Expand Up @@ -183,7 +184,7 @@ public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string o
}
return logger.LogEntries;
}
public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, CancellationToken cancellationToken)
public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken)
{
var globalLogger = new ForwardedLogger<KiotaBuilder>();
var configuration = Configuration.Generation;
Expand All @@ -194,7 +195,7 @@ public async Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, st
configuration.ClientClassName = clientClassName;
configuration.CleanOutput = cleanOutput;
configuration.ClearCache = clearCache;
configuration.Operation = ConsumerOperation.Add; //TODO should be updated to edit in the edit scenario
configuration.Operation = operation;
if (disabledValidationRules is { Length: > 0 })
configuration.DisabledValidationRules = disabledValidationRules.ToHashSet(StringComparer.OrdinalIgnoreCase);
if (pluginTypes is { Length: > 0 })
Expand Down Expand Up @@ -230,6 +231,28 @@ public Task<LanguagesInformation> InfoForDescriptionAsync(string descriptionPath
ArgumentException.ThrowIfNullOrEmpty(descriptionPath);
return InfoInternalAsync(descriptionPath, clearCache, cancellationToken);
}

public async Task<List<LogEntry>> MigrateFromLockFileAsync(string lockDirectoryPath, CancellationToken cancellationToken)
{
ArgumentException.ThrowIfNullOrEmpty(lockDirectoryPath);
var logger = new ForwardedLogger<KiotaBuilder>();
try
{
var workspaceManagementService = new WorkspaceManagementService(logger, httpClient, IsConfigPreviewEnabled.Value);
var clientNames = await workspaceManagementService.MigrateFromLockFileAsync(string.Empty, lockDirectoryPath, cancellationToken).ConfigureAwait(false);
if (!clientNames.Any())
{
logger.LogWarning("no client configuration was migrated");
}
logger.LogInformation("Client configurations migrated successfully: {Clients}", string.Join(", ", clientNames));
}
catch (Exception ex)
{
logger.LogCritical(ex, "error migrating the lock file: {ExceptionMessage}", ex.Message);
}
return logger.LogEntries;
}

private async Task<LanguagesInformation> InfoInternalAsync(string descriptionPath, bool clearCache, CancellationToken cancellationToken)
{
var logger = new ForwardedLogger<KiotaBuilder>();
Expand Down Expand Up @@ -257,7 +280,10 @@ private static PathItem ConvertOpenApiUrlTreeNodeToPathItem(OpenApiUrlTreeNode n
.OrderByDescending(static x => x.isOperation)
.ThenBy(static x => x.segment, StringComparer.OrdinalIgnoreCase)
.ToArray();
return new PathItem(node.Path, node.DeduplicatedSegment(), children, filteredPaths.Count == 0 || Array.Exists(children, static x => x.isOperation) && children.Where(static x => x.isOperation).All(static x => x.selected));
bool isSelected = filteredPaths.Count == 0 || // There are no filtered paths
Array.Exists(children, static x => x.isOperation) && children.Where(static x => x.isOperation).All(static x => x.selected) || // All operations have been selected
!Array.Exists(children, static x => x.isOperation) && Array.TrueForAll(children, static x => x.selected); // All paths selected but no operations present
return new PathItem(node.Path, node.DeduplicatedSegment(), children, isSelected);
}
private static string GetAbsolutePath(string source)
{
Expand Down
26 changes: 25 additions & 1 deletion vscode/microsoft-kiota/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Context: you're most likely a program manager eager to demo the latest bits from
- GitHub CLI `winget install GitHub.CLI`
- dotnet 8 `winget install Microsoft.DotNet.SDK.8`
- node 20 `winget install CoreyButler.NVMforWindows && nvm install lts && nvm use lts`
- vsce & TypeScript `npm i -g TypeScript @vscode/vsce`
- vsce & TypeScript `npm i -g typescript @vscode/vsce`

### Steps

Expand Down Expand Up @@ -46,3 +46,27 @@ Where kiotaVersionInPackage is the kiotaVersion field and versionInPackage is th
> Note: the **.vscode** segment might change to **.vscode-server** if you're remoting to WSL.
> Note: alternatively to building executable yourself, you can download it from [the pipeline](https://github.com/microsoft/kiota/actions/workflows/dotnet.yml) by filtering the branch (top right corner) with the pull request branch, selecting the latest run, and downloading the right OS version from the artifacts. The only remaining work will be to move the downloaded files to the right path above.
#### Using the ready-made script

If you want to automate these steps, you can use the following script to automate the process:

```powershell
.\scripts\execute-vscode-sideload.ps1 -Platform "win-x64|linux-x64|osx-x64"
```

If you are using WSL, you can use the following:

```powershell
.\scripts\execute-vscode-sideload.ps1 -WSL
```

## FAQ

### VS Code keeps reinstalling from the marketplace

This is most likely caused by the fact that there's a newer released version. Run the following script replacing the version argument with the latest version of kiota.

```powershell
.\scripts\update-vscode-releases.ps1 -version "versionWithoutVPrefix" -online -filePath .\vscode\microsoft-kiota\package.json
```
43 changes: 41 additions & 2 deletions vscode/microsoft-kiota/l10n/bundle.l10n.ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"Generating client...": "انشاء العميل...",
"Loading...": "جاري التحميل...",
"Updating clients...": "تحديث العملاء...",
"Pick a lock file": "اختر ملف قفل",
"Open a lock file": "افتح ملف قفل",
"Filter the API description": "قم بتصفية وصف API",
"Enter a filter": "أدخل عامل التصفية",
Expand All @@ -38,5 +37,45 @@
"Invalid URL, please check the documentation for the supported URLs": "عنوان URL غير صالح ، يرجى التحقق من الوثائق الخاصة بعناوين URL المدعومة",
"No content found in the clipboard": "لم يتم العثور على محتوى في الحافظة",
"Invalid content found in the clipboard": "تم العثور على محتوى غير صالح في الحافظة",
"Select an API manifest key": "حدد مفتاح بيان واجهة برمجة التطبيقات"
"Select an API manifest key": "حدد مفتاح بيان واجهة برمجة التطبيقات",
"Edit Paths":"تحرير المسارات",
"Re-generate": "تجديد",
"Add an API description": "إضافة وصف API",
"Search or paste a path to an API description": "ابحث أو الصق مسارًا إلى وصف API",
"Generate a plugin": "إنشاء البرنامج المساعد",
"Generate an API manifest": "إنشاء بيان API",
"What do you want to generate?" : "ماذا تريد أن تولد؟",
"Select an option": " حدد خيارًا",
"class": "فئة",
"namespace": "مساحة الاسم",
"output directory": "مجلد الإخراج",
"language": "لغة",
"Create a new API client": "إنشاء عميل API جديد",
"Create a new plugin": "إنشاء مكون إضافي جديد",
"Create a new manifest": "إنشاء بيان API جديد",
"plugin name:": "اسم المكون الإضافي",
"Choose a name for the plugin": "اختر اسمًا للمكون الإضافي",
"Choose a plugin type": "اختر نوع البرنامج المساعد",
"manifest name": "اسم واضح",
"Choose a name for the manifest": "اختر اسمًا للبيان",
"Required": "مطلوب",
"Open installation instructions for kiota?": "هل تريد فتح تعليمات التثبيت لـ kiota؟",
"Invalid generation type": "نوع الجيل غير صالح",
"Yes, override it": "نعم، تجاوزه",
"Before adding a new API description, consider that your changes and current selection will be lost.": "قبل إضافة وصف جديد لواجهة برمجة التطبيقات، ضع في اعتبارك أنه سيتم فقدان التغييرات والاختيار الحالي.",
"Cancel": "يلغي",
"Do you want to remove this API description?": "هل تريد إزالة وصف API هذا؟",
"Please save the workspace.json file before re-generation.": "يرجى حفظ ملف workspace.json قبل إعادة الإنشاء.",
"OK": "حسنا",
"Generating manifest...": "جارٍ إنشاء البيان...",
"Generating plugin...": "جارٍ إنشاء البرنامج المساعد...",
"Re-generating client...": "إعادة إنشاء العميل...",
"Re-generating plugin...": "إعادة إنشاء البرنامج المساعد...",
"Please migrate your API clients to Kiota workspace.":"يرجى ترحيل عملاء API الخاصين بك إلى مساحة العمل Kiota.",
"Remind me later":"ذكرني لاحقًا",
"Migrating your API clients...": "جاري ترحيل عملاء API الخاصين بك...",
"Migration completed, but no changes were detected.": "تم الانتهاء من الترحيل، ولكن لم يتم اكتشاف أي تغييرات.",
"Migration failed":"فشل الترحيل",
"API clients migrated successfully!":"تم ترحيل عملاء API بنجاح!",
"Could not determine the workspace folder.": "لا يمكن تحديد مجلد مساحة العمل."
}
43 changes: 41 additions & 2 deletions vscode/microsoft-kiota/l10n/bundle.l10n.cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"Generating client...": "Generování klienta...",
"Updating clients...": "Aktualizace klientů...",
"Loading...": "Načítání...",
"Pick a lock file": "Vybrat soubor zámku",
"Open a lock file": "Otevřít soubor zámku",
"Filter the API description": "Filtrovat popis API",
"Enter a filter": "Zadejte filtr",
Expand All @@ -38,5 +37,45 @@
"Invalid URL, please check the documentation for the supported URLs": "Neplatná URL adresa, zkontrolujte dokumentaci pro podporované URL adresy",
"No content found in the clipboard": "V schránce nebyl nalezen žádný obsah",
"Invalid content found in the clipboard": "V schránce byl nalezen neplatný obsah",
"Select an API manifest key": "Vyberte klíč manifestu API"
"Select an API manifest key": "Vyberte klíč manifestu API",
"Edit Paths":"Upravit cesty",
"Re-generate": "Znovu vygenerovat",
"Add an API description": "Přidat popis API",
"Search or paste a path to an API description": "Hledat nebo vložit cestu k popisu API",
"Generate a plugin": "Generovat plugin",
"Generate an API manifest": "Generovat API manifest",
"What do you want to generate?": "Co chcete generovat? ",
"Select an option": "Vyberte možnost",
"class": "třída",
"namespace": "jmenný prostor",
"output directory": "výstupní adresář",
"language": "jazyk",
"Create a new API client": "Vytvořit nového API klienta",
"Create a new plugin": "Vytvořit nový plugin",
"Create a new manifest": "Vytvořit nový manifest",
"plugin name:": "název pluginu",
"Choose a name for the plugin": "Vyberte název pro plugin",
"Choose a plugin type": "Vyberte typ pluginu",
"manifest name": "název manifestu",
"Choose a name for the manifest": "Vyberte název pro manifest",
"Required": "Požadováno",
"Open installation instructions for kiota?": "Otevřít instalační pokyny pro kiota",
"Invalid generation type": "Neplatný typ generování",
"Yes, override it": "Ano, přepsat",
"Before adding a new API description, consider that your changes and current selection will be lost.": "Před přidáním nového popisu API zvažte, že vaše změny a aktuální výběr budou ztraceny.",
"Cancel": "Zrušit",
"Do you want to remove this API description?": "Chcete odstranit tento popis API?",
"Please save the workspace.json file before re-generation.": "Před generováním prosím uložte soubor workspace.json",
"OK": "OK",
"Generating manifest...": "Generování manifestu...",
"Generating plugin...": "Generování pluginu...",
"Re-generating client...": "Opětovné generování klienta...",
"Re-generating plugin...": "Opětovné generování pluginu...",
"Please migrate your API clients to Kiota workspace.":"Prosím, přesuňte své klienty API do pracovního prostoru Kiota.",
"Remind me later":"Připomeňte mi to později",
"Migrating your API clients...":"Přesouvání vašich klientů API…",
"Migration completed, but no changes were detected.":"Migrace dokončena, ale nebyly zjištěny žádné změny.",
"Migration failed":"Migrace selhala.",
"API clients migrated successfully!":"Klienti API byli úspěšně přesunuti!",
"Could not determine the workspace folder.": "Nepodařilo se určit složku pracovního prostoru."
}
Loading

0 comments on commit 9b94384

Please sign in to comment.