Skip to content

Commit 5ae8856

Browse files
Add Project Reference
1 parent 56f6400 commit 5ae8856

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"type": "extensionHost",
99
"runtimeExecutable": "${execPath}",
1010
"args": ["--extensionDevelopmentPath=${workspaceRoot}/release" ],
11-
"stopOnEntry": false
11+
"stopOnEntry": false,
12+
"request": "launch"
1213
}
1314
]
1415
}

paket.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ GIT
2424
(90423567453c82104e852a188640cbfad5882aaa)
2525
build: build.cmd LocalRelease
2626
remote: https://github.com/fsprojects/Forge.git
27-
(7846e65d45a47585be9a2338f3da0de9406b9127)
27+
(b2ce55cfb380ef898aae7b46d7e4eda839fb6707)
2828
build: build.cmd
2929
remote: [email protected]:ionide/ionide-fsgrammar.git
3030
(77ad35a24efc2d0acc84402250589a7f24b803ea)

release/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
{
102102
"command": "fsharp.RemoveFileFromProject",
103103
"title": "F#: Remove Current File From Project"
104+
},
105+
{
106+
"command": "fsharp.AddProjectReference",
107+
"title": "F#: Add Project Reference"
104108
}
105109
],
106110
"outputChannels": [
@@ -138,7 +142,8 @@
138142
"onCommand:fsharp.Methods",
139143
"onCommand:webpreview.Show",
140144
"onCommand:fsharp.NewProject",
141-
"onCommand:fsharp.RefreshProjectTemplates"
145+
"onCommand:fsharp.RefreshProjectTemplates",
146+
"onCommand:fsharp.AddProjectReference"
142147
],
143148
"extensionDependencies": [
144149
"vscode.fsharp"

src/Components/Forge.fs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,27 @@ module Forge =
7070
let editor = vscode.window.Globals.activeTextEditor
7171
if editor.document.languageId = "fsharp" then
7272
sprintf "remove file -n %s" editor.document.fileName |> spawnForge |> ignore
73-
73+
74+
let addProjectReference () =
75+
let projects = Project.getAll () |> List.toArray
76+
if projects.Length <> 0 then
77+
projects
78+
|> Promise.lift
79+
|> fun n ->
80+
let opts = createEmpty<QuickPickOptions>()
81+
opts.placeHolder <- "Project to edit"
82+
window.Globals.showQuickPick(n,opts)
83+
|> Promise.toPromise
84+
|> Promise.success (fun edit ->
85+
let opts = createEmpty<QuickPickOptions>()
86+
opts.placeHolder <- "Reference"
87+
window.Globals.showQuickPick(n,opts)
88+
|> Promise.toPromise
89+
|> Promise.success (fun n ->
90+
sprintf "add project -n %s -p %s" n edit |> spawnForge |> ignore
91+
) )
92+
|> ignore
93+
7494
let newProject () =
7595
"list templates"
7696
|> execForge
@@ -116,4 +136,5 @@ module Forge =
116136
commands.Globals.registerCommand("fsharp.RefreshProjectTemplates", refreshTemplates |> unbox) |> ignore
117137
commands.Globals.registerTextEditorCommand("fsharp.AddFileToProject", addCurrentFileToProject |> unbox) |> ignore
118138
commands.Globals.registerTextEditorCommand("fsharp.RemoveFileFromProject", removeCurrentFileFromProject |> unbox) |> ignore
139+
commands.Globals.registerCommand("fsharp.AddProjectReference", addProjectReference |> unbox) |> ignore
119140
()

src/Core/Project.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ module Project =
5151
| null -> []
5252
| rootPath -> rootPath |> findProjs
5353

54+
let getAll () =
55+
let rec findProjs dir =
56+
let files = Globals.readdirSync dir
57+
files
58+
|> Array.toList
59+
|> List.collect(fun s' ->
60+
try
61+
let s = dir + Globals.sep + s'
62+
if s' = ".git" || s' = "paket-files" then
63+
[]
64+
elif Globals.statSync(s).isDirectory () then
65+
findProjs (s)
66+
else
67+
if s.EndsWith ".fsproj" || s.EndsWith ".csproj" || s.EndsWith ".vbproj" then [ s ] else []
68+
with
69+
| _ -> []
70+
)
71+
72+
match workspace.Globals.rootPath with
73+
| null -> []
74+
| rootPath -> rootPath |> findProjs
75+
76+
5477
let activate () =
5578
match findAll () with
5679
| [] -> Promise.lift (null |> unbox)

0 commit comments

Comments
 (0)