Skip to content

Commit 5f536ec

Browse files
authored
BugFix/overcome the problem with URI in windows (#118)
1 parent b19e76d commit 5f536ec

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/services/languages/go/methodExtractor.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,41 @@ import { DocumentSymbol, SymbolKind } from "vscode-languageclient";
44
import { IMethodExtractor, SymbolInfo } from "../extractors";
55
import { Logger } from '../../logger';
66

7-
export class GoMethodExtractor implements IMethodExtractor{
7+
export class GoMethodExtractor implements IMethodExtractor {
88
public async extractMethods(document: vscode.TextDocument, docSymbols: DocumentSymbol[]): Promise<SymbolInfo[]> {
9-
const methodSymbols = docSymbols.filter(s => s.kind+1 === SymbolKind.Method || s.kind+1 === SymbolKind.Function);
10-
if(!methodSymbols.length)
9+
const methodSymbols = docSymbols.filter(s => s.kind + 1 === SymbolKind.Method || s.kind + 1 === SymbolKind.Function);
10+
if (!methodSymbols.length) {
1111
return [];
12+
}
1213

13-
const modFiles = await vscode.workspace.findFiles('**/go.mod');
14-
const modFile = modFiles.find(f => document.uri.path.startsWith(path.dirname(f.path)))
15-
if(!modFile){
16-
Logger.warn(`Could not resolve mod file for '${document.uri.path}'`)
14+
const modFiles = await (await vscode.workspace.findFiles('**/go.mod')).map(x => x.fsPath);
15+
const normDocPath = document.uri.fsPath;
16+
const modFile = modFiles.find(f => normDocPath.startsWith(path.dirname(f)));
17+
if (!modFile) {
18+
Logger.warn(`Could not resolve mod file for '${document.uri.path}'`);
1719
return [];
1820
}
1921

20-
const modFolder = path.dirname(modFile.path);
21-
const docFolder = path.dirname(document.uri.path);
22+
const modFolder = path.dirname(modFile);
23+
const docFolder = path.dirname(normDocPath);
2224
let packageName = '';
23-
if(modFolder === docFolder){
25+
if (modFolder === docFolder) {
2426
const match = document.getText().match(/^package (.+)$/m);
25-
if(!match){
26-
Logger.warn(`Could not found packakge name in '${document.uri.path}'`)
27+
if (!match) {
28+
Logger.warn(`Could not found packakge name in '${document.uri.path}'`);
2729
return [];
2830
}
29-
packageName = match[1];
31+
packageName = match[1];
3032
}
31-
if(!packageName || packageName !== 'main'){
33+
if (!packageName || packageName !== 'main') {
3234
const modDocument = await vscode.workspace.openTextDocument(modFile);
3335
const match = modDocument.getText().match(/^module (.+)$/m);
34-
if(!match){
35-
Logger.warn(`Could not found module name in '${modFile.path}'`)
36+
if (!match) {
37+
Logger.warn(`Could not found module name in '${modFile}'`);
3638
return [];
3739
}
38-
packageName = match[1]
39-
40+
packageName = match[1];
41+
4042
if (modFolder !== docFolder) {
4143
const relative = path.relative(modFolder, docFolder)
4244
.replaceAll('\\', '/'); // get rid of windows backslashes
@@ -55,10 +57,10 @@ export class GoMethodExtractor implements IMethodExtractor{
5557
new vscode.Position(s.range.start.line, s.range.start.character),
5658
new vscode.Position(s.range.end.line, s.range.end.character)
5759
)
58-
}
60+
};
5961
});
6062

6163
return methods;
6264
}
63-
65+
6466
}

0 commit comments

Comments
 (0)