Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored Nov 5, 2023
1 parent 5620953 commit e3dde49
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 20 deletions.
74 changes: 70 additions & 4 deletions src/azure-pipelines-vscode-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,84 @@ Sample Debugging configuration
"request": "launch",
"name": "Test Pipeline (watch)",
"program": "${workspaceFolder}/azure-pipeline.yml",
"repositories": {},
"parameters": {},
"variables": {},
"repositories": {
"myrepo@windows": "file:///C:/AzurePipelines/myrepo",
"myrepo@unix": "file:///AzurePipelines/myrepo",
"myrepo@github": "vscode-vfs://github/AzurePipelines/myrepo", // Only default branch, url doesn't accept readable ref
"myrepo@azure": "vscode-vfs://azurerepos/AzurePipelines/myrepo/myrepo" // Only default branch, url doesn't accept readable ref
},
"parameters": {
"booleanparam": true,
"numberparam": 12,
"stringparam": "Hello World",
"objectparam": {
"booleanparam": true,
"numberparam": 12,
"stringparam": "Hello World",
},
"arrayparam": [
true,
12,
"Hello World"
]
},
"variables": {
"system.debug": "true"
},
"watch": true,
"preview": true
}
```

Sample Pipeline which dumps the parameters object (legacy parameters syntax)
```yaml
parameters:
booleanparam:
numberparam:
stringparam:
objectparam:
arrayparam:
steps:
- script: echo '${{ converttojson(parameters) }}'
- script: echo '${{ converttojson(variables) }}'
```
Output of the Sample Pipeline
```yaml
stages:
- stage:
jobs:
- job:
steps:
- task: CmdLine@2
inputs:
script: |-
echo '{
"booleanparam": true,
"numberparam": 12,
"stringparam": "Hello World",
"objectparam": {
"booleanparam": true,
"numberparam": 12,
"stringparam": "Hello World"
},
"arrayparam": [
true,
12,
"Hello World"
]
}'
- task: CmdLine@2
inputs:
script: |-
echo '{
"system.debug": "true"
}'
```
## Pros
- Make changes in multiple dependent template files and show a live preview on save
- Everything is done locally
- Whole template engine is open source
- You can run template files with the same template engine locally using the Runner.Client tool using the official Azure Pipelines Agent
- Fast feedback
- Less trial and error commits
Expand Down
35 changes: 22 additions & 13 deletions src/azure-pipelines-vscode-ext/azure-pipelines-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ export class AzurePipelinesDebugSession extends LoggingDebugSession {
}

protected async launchRequest(response: DebugProtocol.LaunchResponse, args: ILaunchRequestArguments) {
logger.setup(args.trace ? Logger.LogLevel.Verbose : Logger.LogLevel.Stop, false);
logger.setup(args.trace ? Logger.LogLevel.Verbose : Logger.LogLevel.Warn, false);

var self = this;
var message = null;
var requestReOpen = false;
var assumeIsOpen = false;
if(args.preview) {
self.virtualFiles[self.name] = "";
var uri = vscode.Uri.from({
Expand All @@ -87,19 +88,25 @@ export class AzurePipelinesDebugSession extends LoggingDebugSession {
});
var doc = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(doc, { preview: true, viewColumn: vscode.ViewColumn.Two, preserveFocus: true });
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(e => {
if(!vscode.window.tabGroups.all.some(g => g.tabs.some(t => t.input["uri"] && t.input["uri"].toString() === uri.toString()))) {
if(!requestReOpen) {
console.log(`file closed ${self.name}`);
}
requestReOpen = true;
} else {
if(requestReOpen) {
console.log(`file opened ${self.name}`);
var previewIsOpen = () => vscode.window.tabGroups.all.some(g => g.tabs.some(t => t.input["uri"] && t.input["uri"].toString() === uri.toString()));
assumeIsOpen = !previewIsOpen();
if(assumeIsOpen) {
logger.error("failed to detect that the textdocument has been opended as a tab, assume that it is open and don't try to show it multiple times");
} else {
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(e => {
if(!previewIsOpen()) {
if(!requestReOpen) {
console.log(`file closed ${self.name}`);
}
requestReOpen = true;
} else {
if(requestReOpen) {
console.log(`file opened ${self.name}`);
}
requestReOpen = false;
}
requestReOpen = false;
}
}));
}));
}
this.disposables.push(vscode.workspace.onDidCloseTextDocument(adoc => {
if(doc === adoc) {
delete self.virtualFiles[self.name];
Expand All @@ -112,6 +119,7 @@ export class AzurePipelinesDebugSession extends LoggingDebugSession {
if(args.preview) {
if(requestReOpen) {
await vscode.window.showTextDocument(doc, { preview: true, viewColumn: vscode.ViewColumn.Two, preserveFocus: true });
requestReOpen = false;
}
self.virtualFiles[self.name] = result;
self.changed(uri);
Expand All @@ -122,6 +130,7 @@ export class AzurePipelinesDebugSession extends LoggingDebugSession {
if(args.preview) {
if(requestReOpen) {
await vscode.window.showTextDocument(doc, { preview: true, viewColumn: vscode.ViewColumn.Two, preserveFocus: true });
requestReOpen = false;
}
self.virtualFiles[self.name] = errmsg;
self.changed(uri);
Expand Down
5 changes: 2 additions & 3 deletions src/azure-pipelines-vscode-ext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function activate(context) {
var uris = [vscode.Uri.parse(fspathname), vscode.Uri.file(fspathname)];
for(var current of uris) {
var rbase = vscode.workspace.getWorkspaceFolder(current);
var name = vscode.workspace.asRelativePath(current);
var name = vscode.workspace.asRelativePath(current, false);
if(rbase && name) {
base = rbase.uri;
filename = name;
Expand All @@ -207,8 +207,7 @@ function activate(context) {
for(var workspace of vscode.workspace.workspaceFolders) {
if(fspathname.startsWith(workspace.uri.fsPath)) {
base = workspace.uri;
filename = vscode.workspace.asRelativePath(workspace.uri.with({path: workspace.uri.path + "/" + fspathname.substring(workspace.uri.fsPath.length).replace(/[\\\/]+/g, "/")
}));
filename = vscode.workspace.asRelativePath(workspace.uri.with({path: workspace.uri.path + "/" + fspathname.substring(workspace.uri.fsPath.length).replace(/[\\\/]+/g, "/")})), false;
break;
}
}
Expand Down

0 comments on commit e3dde49

Please sign in to comment.