Skip to content

Commit 1012cab

Browse files
committed
some fixes
1 parent 5fdb10d commit 1012cab

File tree

3 files changed

+74
-29
lines changed

3 files changed

+74
-29
lines changed

src/providers/DocumentContentProvider.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,31 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
2828
vfs = config("serverSideEditing");
2929
}
3030
workspaceFolder = workspaceFolder && workspaceFolder !== "" ? workspaceFolder : currentWorkspaceFolder();
31-
const found = this.getAsFile(name, workspaceFolder);
32-
if (found) {
33-
return vscode.Uri.file(found);
34-
}
35-
const fileExt = name.split(".").pop();
36-
const fileName = name
37-
.split(".")
38-
.slice(0, -1)
39-
.join(fileExt.match(/cls/i) ? "/" : ".");
40-
name = fileName + "." + fileExt;
41-
let uri = vscode.Uri.file(name).with({
42-
scheme: vfs ? FILESYSTEM_SCHEMA : OBJECTSCRIPT_FILE_SCHEMA,
43-
});
44-
if (workspaceFolder && workspaceFolder !== "") {
45-
uri = uri.with({
46-
authority: workspaceFolder,
31+
const wFolderUri = workspaceFolderUri(workspaceFolder);
32+
let uri: vscode.Uri;
33+
if (wFolderUri.scheme === FILESYSTEM_SCHEMA) {
34+
uri = wFolderUri.with({
35+
path: `/${name}`,
4736
});
37+
} else {
38+
const found = this.getAsFile(name, workspaceFolder);
39+
if (found) {
40+
return vscode.Uri.file(found);
41+
}
42+
const fileExt = name.split(".").pop();
43+
const fileName = name
44+
.split(".")
45+
.slice(0, -1)
46+
.join(fileExt.match(/cls/i) ? "/" : ".");
47+
name = fileName + "." + fileExt;
48+
uri = vscode.Uri.file(name).with({
49+
scheme: vfs ? FILESYSTEM_SCHEMA : OBJECTSCRIPT_FILE_SCHEMA,
50+
});
51+
if (workspaceFolder && workspaceFolder !== "") {
52+
uri = uri.with({
53+
authority: workspaceFolder,
54+
});
55+
}
4856
}
4957
if (namespace && namespace !== "") {
5058
uri = uri.with({

src/providers/ObjectScriptDefinitionProvider.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
22
import { AtelierAPI } from "../api";
3-
import { currentFile, CurrentFile } from "../utils";
3+
import { currentFile, CurrentFile, currentWorkspaceFolder } from "../utils";
44
import { ClassDefinition } from "../utils/classDefinition";
55
import { DocumentContentProvider } from "./DocumentContentProvider";
66

@@ -10,10 +10,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
1010
position: vscode.Position,
1111
token: vscode.CancellationToken
1212
): vscode.ProviderResult<vscode.Location | vscode.Location[] | vscode.DefinitionLink[]> {
13+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
14+
const workspaceFolderName = workspaceFolder ? workspaceFolder.name : currentWorkspaceFolder();
1315
const lineText = document.lineAt(position.line).text;
1416
const file = currentFile();
1517

16-
const fromClassRef = this.classRef(document, position);
18+
const fromClassRef = this.classRef(workspaceFolderName, document, position);
1719
if (fromClassRef) {
1820
return fromClassRef;
1921
}
@@ -39,7 +41,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
3941
const macroMatch = macroText.match(/^\${3}(\b\w+\b)$/);
4042
if (macroMatch) {
4143
const [, macro] = macroMatch;
42-
return this.macro(currentFile(), macro).then(data =>
44+
return this.macro(workspaceFolderName, currentFile(), macro).then(data =>
4345
data && data.document.length
4446
? new vscode.Location(DocumentContentProvider.getUri(data.document), new vscode.Position(data.line, 0))
4547
: null
@@ -53,7 +55,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
5355
const [keyword, name] = part.split(" ");
5456
const start = pos + keyword.length + 1;
5557
if (this.isValid(position, start, name.length)) {
56-
return [this.makeClassDefinition(position, start, name.length, this.normalizeClassName(document, name))];
58+
return [
59+
this.makeClassDefinition(
60+
workspaceFolderName,
61+
position,
62+
start,
63+
name.length,
64+
this.normalizeClassName(document, name)
65+
),
66+
];
5767
}
5868
}
5969
pos += part.length;
@@ -70,7 +80,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
7080
name = name.trim();
7181
const start = pos + part.indexOf(name);
7282
if (this.isValid(position, start, name.length)) {
73-
return this.makeClassDefinition(position, start, name.length, this.normalizeClassName(document, name));
83+
return this.makeClassDefinition(
84+
workspaceFolderName,
85+
position,
86+
start,
87+
name.length,
88+
this.normalizeClassName(document, name)
89+
);
7490
}
7591
})
7692
.filter(el => el != null);
@@ -86,7 +102,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
86102
const start = lineText.indexOf(name);
87103
if (this.isValid(position, start, name.length)) {
88104
return [
89-
this.makeRoutineDefinition(position, start, name.length, this.normalizeRoutineName(document, name, "inc")),
105+
this.makeRoutineDefinition(
106+
workspaceFolderName,
107+
position,
108+
start,
109+
name.length,
110+
this.normalizeRoutineName(document, name, "inc")
111+
),
90112
];
91113
}
92114
}
@@ -103,6 +125,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
103125
if (this.isValid(position, start, name.length)) {
104126
return [
105127
this.makeRoutineDefinition(
128+
workspaceFolderName,
106129
position,
107130
start,
108131
name.length,
@@ -119,6 +142,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
119142
}
120143

121144
public classRef(
145+
workspaceFolder: string,
122146
document: vscode.TextDocument,
123147
position: vscode.Position
124148
): vscode.ProviderResult<vscode.Location | vscode.Location[] | vscode.DefinitionLink[]> {
@@ -129,7 +153,13 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
129153
const start = classRefRange.start.character + 8;
130154
if (this.isValid(position, start, className.length)) {
131155
return [
132-
this.makeClassDefinition(position, start, className.length, this.normalizeClassName(document, className)),
156+
this.makeClassDefinition(
157+
workspaceFolder,
158+
position,
159+
start,
160+
className.length,
161+
this.normalizeClassName(document, className)
162+
),
133163
];
134164
} else {
135165
const classDefinition = new ClassDefinition(className);
@@ -180,6 +210,7 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
180210
}
181211

182212
public makeClassDefinition(
213+
workspaceFolder: string,
183214
position: vscode.Position,
184215
start: number,
185216
length: number,
@@ -192,11 +223,12 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
192223
new vscode.Position(position.line, start + length)
193224
),
194225
targetRange: new vscode.Range(firstLinePos, firstLinePos),
195-
targetUri: DocumentContentProvider.getUri(name),
226+
targetUri: DocumentContentProvider.getUri(name, workspaceFolder),
196227
};
197228
}
198229

199230
public makeRoutineDefinition(
231+
workspaceFolder: string,
200232
position: vscode.Position,
201233
start: number,
202234
length: number,
@@ -209,11 +241,15 @@ export class ObjectScriptDefinitionProvider implements vscode.DefinitionProvider
209241
new vscode.Position(position.line, start + length)
210242
),
211243
targetRange: new vscode.Range(firstLinePos, firstLinePos),
212-
targetUri: DocumentContentProvider.getUri(name),
244+
targetUri: DocumentContentProvider.getUri(name, workspaceFolder),
213245
};
214246
}
215247

216-
public async macro(file: CurrentFile, macro: string): Promise<{ document: string; line: number }> {
248+
public async macro(
249+
workspaceFolder: string,
250+
file: CurrentFile,
251+
macro: string
252+
): Promise<{ document: string; line: number }> {
217253
const fileName = file.name;
218254
const api = new AtelierAPI();
219255
let includes = [];

src/utils/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ export async function mkdirSyncRecursive(dirpath: string): Promise<string> {
7777
});
7878
}
7979

80-
export function currentWorkspaceFolder(): string {
80+
export function currentWorkspaceFolder(document?: vscode.TextDocument): string {
8181
let workspaceFolder;
82-
if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document) {
83-
const uri = vscode.window.activeTextEditor.document.uri;
82+
document = document ? document : vscode.window.activeTextEditor && vscode.window.activeTextEditor.document;
83+
if (document) {
84+
const uri = document.uri;
8485
if (uri.scheme === "file") {
8586
if (vscode.workspace.getWorkspaceFolder(uri)) {
8687
workspaceFolder = vscode.workspace.getWorkspaceFolder(uri).name;

0 commit comments

Comments
 (0)