Skip to content

Commit b8b65e4

Browse files
authored
Merge pull request #162 from alefragnani/feature/support-new-file
Feature/support new file
2 parents 82f120f + ea4c65d commit b8b65e4

File tree

9 files changed

+166
-2
lines changed

9 files changed

+166
-2
lines changed

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@
9393
}
9494
],
9595
"commands": [
96+
{
97+
"command": "pascal.newFile",
98+
"title": "%pascal.commands.newFile.title%"
99+
},
100+
{
101+
"command": "pascal.newClassFile",
102+
"title": "%pascal.commands.newClassFile.title%"
103+
},
104+
{
105+
"command": "pascal.newInterfaceFile",
106+
"title": "%pascal.commands.newInterfaceFile.title%"
107+
},
108+
{
109+
"command": "pascal.newProgramFile",
110+
"title": "%pascal.commands.newProgramFile.title%"
111+
},
96112
{
97113
"command": "pascal.generateTags",
98114
"title": "%pascal.commands.generateTags.title%",
@@ -149,6 +165,20 @@
149165
"group": "pascal",
150166
"when": "extension == alefragnani.pascal && extensionStatus == installed"
151167
}
168+
],
169+
"file/newFile": [
170+
{
171+
"command": "pascal.newFile"
172+
},
173+
{
174+
"command": "pascal.newClassFile"
175+
},
176+
{
177+
"command": "pascal.newInterfaceFile"
178+
},
179+
{
180+
"command": "pascal.newProgramFile"
181+
}
152182
]
153183
},
154184
"configuration": {

package.nls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"pascal.configuration.title": "Pascal",
33
"pascal.configuration.tags.autoGenerate.description": "Controls if the extension should automatically generate tags in projects opened for the first time",
44
"pascal.configuration.codeNavigation.description": "Select how the code navigation should work",
5+
"pascal.commands.newFile.title": "Pascal: New File",
6+
"pascal.commands.newClassFile.title": "Pascal: New Class File",
7+
"pascal.commands.newInterfaceFile.title": "Pascal: New Interface File",
8+
"pascal.commands.newProgramFile.title": "Pascal: New Program File",
59
"pascal.commands.generateTags.title": "Pascal: Generate Tags",
610
"pascal.commands.updateTags.title": "Pascal: Update Tags",
711
"pascal.commands.whatsNew.title": "Pascal: What's New",

src/commands/newFiles.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { commands } from 'vscode';
7+
import { newFile } from '../newFile/newFile';
8+
import { newClassFile } from '../newFile/newClassFile';
9+
import { newInterfaceFile } from '../newFile/newInterfaceFile';
10+
import { newProgramFile } from '../newFile/newProgramFile';
11+
import { Container } from '../container';
12+
13+
export function registerNewFileCommands() {
14+
Container.context.subscriptions.push(
15+
commands.registerCommand("pascal.newFile", async () => newFile())
16+
);
17+
Container.context.subscriptions.push(
18+
commands.registerCommand("pascal.newClassFile", async () => newClassFile())
19+
);
20+
Container.context.subscriptions.push(
21+
commands.registerCommand("pascal.newInterfaceFile", async () => newInterfaceFile())
22+
);
23+
Container.context.subscriptions.push(
24+
commands.registerCommand("pascal.newProgramFile", async () => newProgramFile())
25+
);
26+
}

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ import { registerWhatsNew } from './whats-new/commands';
1010
import { registerGenerateTags } from './commands/generateTags';
1111
import { registerProviders } from './providers';
1212
import { registerWalkthrough } from "./commands/walkthrough";
13+
import { registerNewFileCommands } from './commands/newFiles';
1314

1415
// this method is called when your extension is activated
1516
// your extension is activated the very first time the command is executed
1617
export async function activate(context: vscode.ExtensionContext) {
17-
1818
Container.context = context;
1919

2020
await registerWhatsNew();
2121
registerProviders();
2222
registerGenerateTags();
2323
registerWalkthrough();
24+
registerNewFileCommands();
2425

2526
vscode.workspace.onDidGrantWorkspaceTrust(() => {
2627
registerProviders();
2728
registerGenerateTags();
2829
})
2930

30-
}
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
8+
export async function createNewFileFromSnippetString(content: vscode.SnippetString) {
9+
const document = await vscode.workspace.openTextDocument({ language: "pascal" });
10+
const editor = await vscode.window.showTextDocument(document);
11+
editor.insertSnippet(content);
12+
}

src/newFile/newClassFile.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { createNewFileFromSnippetString } from './createNewFileFromSnippetString';
8+
9+
export async function newClassFile() {
10+
const snippet = new vscode.SnippetString(
11+
"unit ${1:UnitName};\n\n" +
12+
"interface\n\n" +
13+
"uses\n" +
14+
" Classes;\n\n" +
15+
"type\n" +
16+
" T${2:ClassName} = class\n" +
17+
" public\n" +
18+
" constructor Create;\n" +
19+
" end;\n\n" +
20+
"implementation\n\n" +
21+
"constructor T${2:ClassName}.Create;\n" +
22+
"begin\n" +
23+
" inherited Create;\n" +
24+
" $0\n" +
25+
"end;\n\n" +
26+
"end."
27+
);
28+
createNewFileFromSnippetString(snippet);
29+
}

src/newFile/newFile.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { createNewFileFromSnippetString } from './createNewFileFromSnippetString';
8+
9+
export async function newFile() {
10+
const snippet = new vscode.SnippetString(
11+
"unit ${1:UnitName};\n\n" +
12+
"interface\n\n" +
13+
"uses\n" +
14+
" Classes;\n\n" +
15+
"$0\n" +
16+
"implementation\n\n" +
17+
"end."
18+
);
19+
createNewFileFromSnippetString(snippet);
20+
}

src/newFile/newInterfaceFile.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { createNewFileFromSnippetString } from './createNewFileFromSnippetString';
8+
9+
export async function newInterfaceFile() {
10+
const snippet = new vscode.SnippetString(
11+
"unit ${1:UnitName};\n\n" +
12+
"interface\n\n" +
13+
"uses\n" +
14+
" Classes;\n\n" +
15+
"type\n" +
16+
" I${2:ClassName} = interface\n" +
17+
" $0\n" +
18+
" end;\n\n" +
19+
"implementation\n\n" +
20+
"end."
21+
);
22+
createNewFileFromSnippetString(snippet);
23+
}

src/newFile/newProgramFile.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Alessandro Fragnani. All rights reserved.
3+
* Licensed under the MIT License. See License.md in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { createNewFileFromSnippetString } from './createNewFileFromSnippetString';
8+
9+
export async function newProgramFile() {
10+
const snippet = new vscode.SnippetString(
11+
"program ${1:ProgramName};\n\n" +
12+
"uses\n" +
13+
" Classes;\n\n" +
14+
"begin\n" +
15+
" $0\n" +
16+
"end."
17+
);
18+
createNewFileFromSnippetString(snippet);
19+
}

0 commit comments

Comments
 (0)