Skip to content

Commit b62087b

Browse files
committed
Adding go mod parser
1 parent c6bcad5 commit b62087b

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/vs/workbench/contrib/tags/electron-sandbox/workspaceTagsService.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -801,21 +801,36 @@ export class WorkspaceTagsService implements IWorkspaceTagsService {
801801
const goModPromises = getFilePromises('go.mod', this.fileService, this.textFileService, content => {
802802
// TODO: Richard to write the code for parsing the go.mod file
803803
// look for everything in require() and get the string value only discard version
804-
const dependencies: string[] = splitLines(content.value);
805-
for (const dependency of dependencies) {
806-
// Dependencies in requirements.txt can have 3 formats: `foo==3.1, foo>=3.1, foo`
807-
const format1 = dependency.split('==');
808-
const format2 = dependency.split('>=');
809-
const packageName = (format1.length === 2 ? format1[0] : format2[0]).trim();
804+
const lines: string[] = splitLines(content.value);
805+
let firstRequireBlockFound: boolean = false;
806+
807+
for (let i = 0; i < lines.length; i++) {
808+
const line: string = lines[i].trim();
809+
810+
if (line.startsWith('require (')) {
811+
if (!firstRequireBlockFound) {
812+
firstRequireBlockFound = true;
813+
continue;
814+
} else {
815+
break;
816+
}
817+
}
810818

811-
// copied from line 728 function addPythonTags
812-
if (GoModulesToLookFor.indexOf(packageName) > -1) {
813-
tags['workspace.go.mod' + packageName] = true;
819+
if (line.startsWith(')')) {
820+
break;
814821
}
815-
// not sure if we should keep this
816-
for (const metaModule of GoMetaModulesToLookFor) {
817-
if (packageName.startsWith(metaModule)) {
818-
tags['workspace.go.mod' + metaModule] = true;
822+
823+
if (firstRequireBlockFound && line !== '') {
824+
const packageName: string = line.split(' ')[0].trim();
825+
// copied from line 728 function addPythonTags
826+
if (GoModulesToLookFor.indexOf(packageName) > -1) {
827+
tags['workspace.go.mod' + packageName] = true;
828+
}
829+
// not sure if we should keep this
830+
for (const metaModule of GoMetaModulesToLookFor) {
831+
if (packageName.startsWith(metaModule)) {
832+
tags['workspace.go.mod' + metaModule] = true;
833+
}
819834
}
820835
}
821836
}

0 commit comments

Comments
 (0)