-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: use v1 snippets when v1 is enabled on cluster (#725) Signed-off-by: Luca Stocchi <[email protected]> * fix trigger snippets Signed-off-by: Luca Stocchi <[email protected]> Signed-off-by: Luca Stocchi <[email protected]>
- Loading branch information
Showing
16 changed files
with
120 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
apiVersion: <pipelines_api_version> | ||
kind: Task | ||
metadata: | ||
name: ${1} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import {CompletionItem, CompletionItemProvider as ICompletionItemProvider, SnippetString} from 'vscode'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { contextGlobalState } from '../extension'; | ||
import { Snippet } from './snippet'; | ||
import * as semver from 'semver'; | ||
|
||
export default class TektonCompletionItemProvider implements ICompletionItemProvider { | ||
private newestVersion: string; | ||
public readonly encoding = 'utf-8'; | ||
private readonly tektonSnippetsFile = path.join(contextGlobalState.extensionPath, 'snippets/tekton.json'); | ||
protected items: CompletionItem[]; | ||
|
||
constructor(newestVersion: string) { | ||
this.newestVersion = newestVersion; | ||
this.items = []; | ||
} | ||
|
||
public init(): Thenable<ICompletionItemProviderInitResult> { | ||
return this.generateItems(); | ||
} | ||
|
||
public update(newestVersion: string): Thenable<ICompletionItemProviderInitResult> { | ||
this.newestVersion = newestVersion; | ||
this.items = []; | ||
return this.generateItems(); | ||
} | ||
|
||
private generateItems(): Thenable<ICompletionItemProviderInitResult> { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(this.tektonSnippetsFile, this.encoding, (readFileError, data) => { | ||
if (readFileError) { | ||
resolve(<ICompletionItemProviderInitResult>{success: false, error: readFileError}); | ||
} | ||
else { | ||
try { | ||
let version = 'tekton.dev/v1beta1'; | ||
if (this.newestVersion | ||
&& this.newestVersion !== 'unknown' | ||
&& semver.satisfies(this.newestVersion.replace('v',''), '>=0.43.0')) { | ||
version = 'tekton.dev/v1'; | ||
} | ||
const dataAsJson: Map<string, Snippet<string[]>> = JSON.parse(data); | ||
for (const key in dataAsJson) { | ||
const body: string[] = dataAsJson[key].body; | ||
const bodyAsString = body.join('\n').replace('<pipelines_api_version>', version); | ||
const completionItem: CompletionItem = { | ||
label: key, | ||
detail: dataAsJson[key].description, | ||
insertText: new SnippetString(bodyAsString), | ||
}; | ||
this.items.push(completionItem); | ||
} | ||
|
||
resolve(<ICompletionItemProviderInitResult>{success: true, error: undefined}); | ||
} | ||
catch (error) { | ||
resolve(<ICompletionItemProviderInitResult>{success: false, error: error}); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
public provideCompletionItems(): CompletionItem[] { | ||
return this.items; | ||
} | ||
} | ||
|
||
export interface ICompletionItemProviderInitResult { | ||
success: boolean; | ||
error: Error; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters