Skip to content

Commit 85576f7

Browse files
committed
lanuage configuration, formatter, search on server
1 parent 601f066 commit 85576f7

16 files changed

+839
-33
lines changed

src/api/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export class AtelierAPI {
4949
this.setConnection(workspaceFolderName || currentWorkspaceFolder());
5050
}
5151

52+
public get enabled(): boolean {
53+
return this.config.active;
54+
}
55+
5256
public setNamespace(namespace: string) {
5357
this.namespace = namespace;
5458
}
@@ -261,7 +265,7 @@ export class AtelierAPI {
261265
word?: boolean;
262266
}): Promise<any> {
263267
params = {
264-
files: "*.cls,*.mac,*.inc",
268+
files: "*.cls,*.mac,*.int,*.inc",
265269
gen: false,
266270
sys: false,
267271
regex: false,

src/atelier.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export interface AtelierSearchMatch {
2+
text: string;
3+
line?: number;
4+
member?: string;
5+
attr?: string;
6+
attrline?: number;
7+
}
8+
9+
export interface AtelierSearchResult {
10+
doc: string;
11+
matches: AtelierSearchMatch[];
12+
}
13+
14+
export interface AtelierJob {
15+
pid: number;
16+
namespace: string;
17+
routine: string;
18+
state: string;
19+
device: string;
20+
}

src/debug/dbgp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class DbgpConnection extends EventEmitter {
102102
},
103103
},
104104
});
105+
console.log(xml);
105106
const document = parser.parseFromString(xml, "application/xml");
106107
this.emit("message", document);
107108
// reset buffer

src/debug/xdebugConnection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ export class Connection extends DbgpConnection {
910910
const data = iconv.encode(commandString, ENCODING);
911911
this._pendingCommands.set(transactionId, command);
912912
this._pendingExecuteCommand = command.isExecuteCommand;
913+
console.log(data.toString());
913914
await this.write(data);
914915
}
915916

src/extension.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import vscode = require("vscode");
2+
import { AtelierJob } from "./atelier";
23
const { workspace, window } = vscode;
34
export const OBJECTSCRIPT_FILE_SCHEMA = "objectscript";
45
export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml";
56
export const FILESYSTEM_SCHEMA = "isfs";
67
export const schemas = [OBJECTSCRIPT_FILE_SCHEMA, OBJECTSCRIPTXML_FILE_SCHEMA, FILESYSTEM_SCHEMA];
7-
import { AtelierJob } from "./models";
88

99
import { importAndCompile, importFolder as importFileOrFolder, namespaceCompile } from "./commands/compile";
1010
import { deleteItem } from "./commands/delete";
@@ -15,6 +15,8 @@ import { superclass } from "./commands/superclass";
1515
import { viewOthers } from "./commands/viewOthers";
1616
import { xml2doc } from "./commands/xml2doc";
1717

18+
import { getLanguageConfiguration } from "./languageConfiguration";
19+
1820
import { DocumentContentProvider } from "./providers/DocumentContentProvider";
1921
import { DocumentFormattingEditProvider } from "./providers/DocumentFormattingEditProvider";
2022
import { ObjectScriptClassFoldingRangeProvider } from "./providers/ObjectScriptClassFoldingRangeProvider";
@@ -33,8 +35,12 @@ import { ObjectScriptConfigurationProvider } from "./debug/debugConfProvider";
3335
import { ObjectScriptExplorerProvider } from "./explorer/explorer";
3436
import { WorkspaceNode } from "./explorer/models/workspaceNode";
3537
import { FileSystemProvider } from "./providers/FileSystemPovider/FileSystemProvider";
38+
import { FileSearchProvider } from "./providers/FileSystemPovider/FileSearchProvider";
39+
import { TextSearchProvider } from "./providers/FileSystemPovider/TextSearchProvider";
3640
import { WorkspaceSymbolProvider } from "./providers/WorkspaceSymbolProvider";
3741
import { currentWorkspaceFolder, outputChannel } from "./utils";
42+
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
43+
import { DocumentRangeFormattingEditProvider } from "./providers/DocumentRangeFormattingEditProvider";
3844
export let fileSystemProvider: FileSystemProvider;
3945
export let explorerProvider: ObjectScriptExplorerProvider;
4046
export let documentContentProvider: DocumentContentProvider;
@@ -143,13 +149,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
143149
}
144150
});
145151

146-
const wordPattern = /("(?:[^"]|"")*")|((\${1,3}|[irm]?%|\^|#)?[^`~!@@#%^&*()-=+[{\]}|;:'",.<>/?_\s]+)/;
147-
148152
const documentSelector = (...list) =>
149153
["file", ...schemas].reduce((acc, scheme) => acc.concat(list.map(language => ({ scheme, language }))), []);
150154

155+
const diagnosticProvider = new ObjectScriptDiagnosticProvider();
156+
if (vscode.window.activeTextEditor) {
157+
diagnosticProvider.updateDiagnostics(vscode.window.activeTextEditor.document);
158+
}
159+
151160
context.subscriptions.push(
152-
window.onDidChangeActiveTextEditor(e => {
161+
workspace.onDidChangeTextDocument(event => {
162+
diagnosticProvider.updateDiagnostics(event.document);
163+
}),
164+
window.onDidChangeActiveTextEditor(editor => {
165+
if (editor) {
166+
diagnosticProvider.updateDiagnostics(editor.document);
167+
}
153168
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 1) {
154169
const workspaceFolder = currentWorkspaceFolder();
155170
if (workspaceFolder && workspaceFolder !== workspaceState.get<string>("workspaceFolder")) {
@@ -220,15 +235,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
220235
vscode.workspace.registerTextDocumentContentProvider(OBJECTSCRIPT_FILE_SCHEMA, documentContentProvider),
221236
vscode.workspace.registerTextDocumentContentProvider(OBJECTSCRIPTXML_FILE_SCHEMA, xmlContentProvider),
222237
vscode.workspace.registerFileSystemProvider(FILESYSTEM_SCHEMA, fileSystemProvider, { isCaseSensitive: true }),
223-
vscode.languages.setLanguageConfiguration("objectscript-class", {
224-
wordPattern,
225-
}),
226-
vscode.languages.setLanguageConfiguration("objectscript", {
227-
wordPattern,
228-
}),
229-
vscode.languages.setLanguageConfiguration("objectscript-macros", {
230-
wordPattern,
231-
}),
238+
vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration()),
239+
vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration()),
240+
vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration()),
232241
vscode.languages.registerDocumentSymbolProvider(
233242
documentSelector("objectscript-class"),
234243
new ObjectScriptClassSymbolProvider()
@@ -265,9 +274,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
265274
documentSelector("objectscript-class", "objectscript", "objectscript-macros"),
266275
new DocumentFormattingEditProvider()
267276
),
277+
vscode.languages.registerDocumentRangeFormattingEditProvider(
278+
documentSelector("objectscript-class", "objectscript", "objectscript-macros"),
279+
new DocumentRangeFormattingEditProvider()
280+
),
268281
vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider()),
269282
vscode.debug.registerDebugConfigurationProvider("objectscript", new ObjectScriptConfigurationProvider()),
270283
vscode.debug.registerDebugAdapterDescriptorFactory("objectscript", debugAdapterFactory),
271-
debugAdapterFactory
284+
debugAdapterFactory,
285+
286+
/* from proposed api */
287+
vscode.workspace.registerFileSearchProvider(FILESYSTEM_SCHEMA, new FileSearchProvider()),
288+
vscode.workspace.registerTextSearchProvider(FILESYSTEM_SCHEMA, new TextSearchProvider())
272289
);
273290
}

src/languageConfiguration.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { IndentAction, LanguageConfiguration } from "vscode";
2+
3+
export const WORD_PATTERN = /((?<=(class|extends|as|of) )(%?\b[a-z0-9]+(\.[a-z0-9]+)*\b))|(\^[a-z0-9]+(\.[a-z0-9]+)*)|((\${1,3}|[irm]?%|\^|#)?[a-z0-9]+)/i;
4+
5+
export function getLanguageConfiguration(): LanguageConfiguration {
6+
return {
7+
wordPattern: WORD_PATTERN,
8+
brackets: [["{", "}"], ["(", ")"], ['"', '"']],
9+
comments: {
10+
lineComment: "#;",
11+
blockComment: ["/*", "*/"],
12+
},
13+
onEnterRules: [
14+
{
15+
beforeText: /^\/\/\//,
16+
afterText: /.*/,
17+
action: { indentAction: IndentAction.None, appendText: "/// " },
18+
},
19+
],
20+
};
21+
}

src/models.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/providers/DocumentFormattingEditProvider.ts

Lines changed: 153 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,174 @@
11
import * as vscode from "vscode";
2-
2+
import { Formatter } from "./Formatter";
33
import commands = require("./completion/commands.json");
4+
import systemFunctions = require("./completion/systemFunctions.json");
5+
import systemVariables = require("./completion/systemVariables.json");
46

57
export class DocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider {
8+
private _formatter: Formatter;
9+
public constructor() {
10+
this._formatter = new Formatter();
11+
}
12+
613
public provideDocumentFormattingEdits(
714
document: vscode.TextDocument,
815
options: vscode.FormattingOptions,
916
token: vscode.CancellationToken
1017
): vscode.ProviderResult<vscode.TextEdit[]> {
18+
return [...this.commands(document, options), ...this.functions(document, options)];
19+
}
20+
21+
private commands(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
1122
const edits = [];
23+
let indent = 1;
1224

1325
for (let i = 0; i < document.lineCount; i++) {
1426
const line = document.lineAt(i);
1527

16-
const commandsMatch = line.text.match(/^\s+(?:}\s)?\b([a-z]+)\b/i);
28+
if (line.text.length && !line.text.trim().length) {
29+
edits.push({
30+
newText: "",
31+
range: line.range,
32+
});
33+
continue;
34+
}
35+
36+
const commentsMatch = line.text.match(/^(\s*)(\/\/+|#+;\s*|;)(.*)/i);
37+
if (commentsMatch) {
38+
const indentSize = options.tabSize * indent;
39+
const [, space, comment] = commentsMatch;
40+
let newText;
41+
if (space === "" && comment.match(/\/{3}/)) {
42+
newText = "";
43+
} else {
44+
newText = " ".repeat(indentSize);
45+
}
46+
47+
if (options.insertSpaces && space.length !== newText.length) {
48+
edits.push({
49+
newText,
50+
range: new vscode.Range(new vscode.Position(i, 0), new vscode.Position(i, space.length)),
51+
});
52+
}
53+
continue;
54+
}
55+
56+
const dotsMatch = line.text.match(/^\s+(\.\s*)+/);
57+
if (dotsMatch) {
58+
const indentSize = options.tabSize;
59+
const [dots] = dotsMatch;
60+
const newText =
61+
" ".repeat(indentSize) +
62+
dots
63+
.split(".")
64+
.slice(1)
65+
.map(() => "." + " ".repeat(indentSize - 1))
66+
.join("");
67+
if (options.insertSpaces && dots.length !== newText.length) {
68+
edits.push({
69+
newText,
70+
range: new vscode.Range(new vscode.Position(i, 0), new vscode.Position(i, dots.length)),
71+
});
72+
}
73+
}
74+
75+
const bracketMatch = line.text.match(/^(\s+)}(.*)$/);
76+
if (bracketMatch) {
77+
indent--;
78+
const indentSize = options.tabSize * indent;
79+
const [, space, rest] = bracketMatch;
80+
if (options.insertSpaces && space.length !== indentSize) {
81+
edits.push({
82+
newText: " ".repeat(indentSize),
83+
range: new vscode.Range(new vscode.Position(i, 0), new vscode.Position(i, space.length)),
84+
});
85+
}
86+
if (rest.trimLeft().length) {
87+
const pos = line.text.indexOf("}") + 1;
88+
edits.push({
89+
newText: "\n" + " ".repeat(indentSize),
90+
range: new vscode.Range(
91+
new vscode.Position(i, pos),
92+
new vscode.Position(i, pos + rest.length - rest.trimLeft().length)
93+
),
94+
});
95+
}
96+
}
97+
98+
const commandsMatch = line.text.match(/^(\s+[\s.]*)\b([a-z]+)\b/i);
1799
if (commandsMatch) {
18-
const [, found] = commandsMatch;
19-
const pos = line.text.indexOf(found);
20-
const command = commands.find(el => el.alias.includes(found.toUpperCase()));
21-
if (command.label !== found) {
22-
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + found.length));
100+
const indentSize = options.tabSize * indent;
101+
const [, space, found] = commandsMatch;
102+
if (!space.includes(".") && options.insertSpaces && space.length !== indentSize) {
103+
const newText = " ".repeat(indentSize);
23104
edits.push({
24-
newText: command.label,
25-
range,
105+
newText,
106+
range: new vscode.Range(new vscode.Position(i, 0), new vscode.Position(i, space.length)),
26107
});
27108
}
109+
const pos = line.text.indexOf(found);
110+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + found.length));
111+
const command = commands.find(el => el.alias.includes(found.toUpperCase()));
112+
if (command) {
113+
const expect = this._formatter.command(command.label);
114+
if (expect !== found) {
115+
edits.push({
116+
newText: expect,
117+
range,
118+
});
119+
}
120+
}
121+
const setAssignMatch = line.text.match(
122+
/^\s+(?:\.\s*)*set\s(?:\^?%?(?:[a-z][a-z0-9]*)(?:\.[a-z][a-z0-9]*)*)(\s*=\s*)/i
123+
);
124+
if (setAssignMatch) {
125+
const [full, assign] = setAssignMatch;
126+
const pos = full.length - assign.length;
127+
const newText = " = ";
128+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + assign.length));
129+
if (assign !== newText) {
130+
edits.push({
131+
newText,
132+
range,
133+
});
134+
}
135+
}
136+
}
137+
138+
if (line.text.match(/^(\w+|{)/)) {
139+
indent = 1;
140+
} else if (line.text.match(/.+{(?!.*})/)) {
141+
indent++;
142+
}
143+
}
144+
145+
return edits;
146+
}
147+
148+
private functions(document: vscode.TextDocument, options: vscode.FormattingOptions): vscode.TextEdit[] {
149+
const edits = [];
150+
151+
for (let i = 0; i < document.lineCount; i++) {
152+
const line = document.lineAt(i);
153+
154+
const pattern = /(?<!\$)(\$\b[a-z]+)\b/gi;
155+
let functionsMatch = null;
156+
while ((functionsMatch = pattern.exec(line.text)) !== null) {
157+
const [, found] = functionsMatch;
158+
const pos = functionsMatch.index;
159+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + found.length));
160+
const systemFunction = [...systemFunctions, ...systemVariables].find(el =>
161+
el.alias.includes(found.toUpperCase())
162+
);
163+
if (systemFunction) {
164+
const expect = this._formatter.function(systemFunction.label);
165+
if (expect !== found) {
166+
edits.push({
167+
newText: expect,
168+
range,
169+
});
170+
}
171+
}
28172
}
29173
}
30174

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as vscode from "vscode";
2+
3+
export class DocumentRangeFormattingEditProvider implements vscode.DocumentRangeFormattingEditProvider {
4+
public provideDocumentRangeFormattingEdits(
5+
document: vscode.TextDocument,
6+
range: vscode.Range,
7+
options: vscode.FormattingOptions,
8+
token: vscode.CancellationToken
9+
): vscode.ProviderResult<vscode.TextEdit[]> {
10+
return null;
11+
}
12+
}

0 commit comments

Comments
 (0)