Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
soicode
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Timon Stampfli
soicode
Commits
dace3cd9
Commit
dace3cd9
authored
Oct 31, 2020
by
Timon Stampfli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unsaved changes
parent
354fbe2f
Pipeline
#5697
failed with stage
in 17 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
355 deletions
+7
-355
src/fs/fs-abstraction.ts
src/fs/fs-abstraction.ts
+5
-0
src/fs/fs.ts
src/fs/fs.ts
+2
-0
src/fs/workspaceTracker/sample.ts
src/fs/workspaceTracker/sample.ts
+0
-129
src/fs/workspaceTracker/soitask.ts
src/fs/workspaceTracker/soitask.ts
+0
-105
src/fs/workspaceTracker/soiworkspace.ts
src/fs/workspaceTracker/soiworkspace.ts
+0
-121
No files found.
src/fs/fs-abstraction.ts
View file @
dace3cd9
...
...
@@ -47,3 +47,8 @@ export class FSAbstraction {
}
private
updateWorkspaceState
(
this
:
Tracker
)
{}
}
export
function
createFSAbstraction
(
context
:
vscode
.
ExtensionContext
,
state
:
State
)
{}
src/fs/fs.ts
View file @
dace3cd9
import
*
as
vscode
from
"
vscode
"
;
import
{
State
}
from
"
../state/state
"
;
import
{
FSAbstraction
}
from
"
./fs-abstraction
"
;
import
{
Tracker
}
from
"
./workspaceTracker/tracker
"
;
...
...
@@ -26,4 +27,5 @@ export class FS {
isReady
(
this
:
FS
):
boolean
{
return
this
.
status
===
"
Ready
"
;
}
startTrackingWorkspace
(
context
:
vscode
.
ExtensionContext
,
state
:
State
)
{}
}
src/fs/workspaceTracker/sample.ts
View file @
dace3cd9
...
...
@@ -13,132 +13,3 @@ export async function readSamples(
let
result
=
decodeSoiTask
(
json
);
return
result
.
samples
;
}
// export async function getTaskStoml(taskname: string | null): Promise<Entry[]> {
// if (taskname === null) {
// let editor = vscode.window.activeTextEditor;
// if (editor === undefined) {
// throw new Error(
// "Can't get stoml if no taskname is passed and no editor is open"
// );
// } else {
// taskname = await filenameToTaskname(editor.document.fileName);
// }
// }
// let soitaskFile = await tasknameToSoitaskFilename(taskname);
// let stoml = (await fs.readFile(soitaskFile)).toString();
// return parseStoml(stoml);
// }
// export function determineSamples(
// soitaskContent: string
// ): Map<string, Entry> | StomlError {
// try {
// let entries = parseStoml(soitaskContent);
// return new Map(
// entries
// .filter(entry => entry.name[0] === "sample")
// .map(entry => [entry.name.join("."), entry])
// );
// } catch (err) {
// if (err instanceof StomlError) {
// return err;
// }
// throw new Error(
// "Unexpected Error happened when parsing the soitask file: " +
// err.toString()
// );
// }
// }
// export async function listSamplesForTaskname(
// store: State,
// taskname: string
// ): Promise<Map<string, Entry>> {
// let path: string;
// try {
// path = getSoitaskFilesOfFulltaskOrError(
// store,
// taskname
// ).soitaskFsPath!.toString();
// } catch (err) {
// return new Map();
// }
// let content: string;
// try {
// content = (await fs.readFile(path)).toString();
// } catch (err) {
// vscode.window.showErrorMessage("Cannot read soitask file");
// throw new Error("Cannot read soitask file");
// }
// let sampleList = determineSamples(content);
// if (sampleList instanceof StomlError) {
// vscode.window.showErrorMessage(
// "Cannot parse soitask. It has the following error: " +
// sampleList.toString()
// );
// throw new Error("Cannot read soitask file");
// }
// return sampleList;
// }
// export async function selectSample(
// store: State,
// taskname: string,
// sample: string | undefined | null
// ): Promise<string> {
// if (typeof sample === "string") {
// return sample;
// }
// let sampleList = await listSamplesForTaskname(store, taskname);
// sample = await vscode.window.showQuickPick(toSortedKeys(sampleList), {
// canPickMany: false,
// placeHolder: "sample.mysample"
// });
// if (sample === undefined) {
// vscode.window.showErrorMessage("No sample has been selected");
// throw new Error("No sample has been selected");
// }
// return sample;
// }
// export async function gotoSample(
// store: State,
// sampleName: string | null | undefined
// ) {
// let editor = vscode.window.activeTextEditor;
// if (editor === undefined) {
// vscode.window.showErrorMessage("No file open");
// throw new Error("No file open");
// }
// let taskname = fspathToTasknameOrError(store, editor.document.fileName);
// sampleName = await selectSample(store, taskname, sampleName);
// let sample = store.samples.get(sampleName);
// if (sample === undefined) {
// vscode.window.showErrorMessage("The selected sample does not exist");
// throw new Error("The selected sample does not exist");
// }
// let loc = new vscode.Range(
// new vscode.Position(sample.span.startLine, 0),
// new vscode.Position(
// sample.span.startLine,
// editor.document.lineAt(sample.span.startLine).range.end.character
// )
// );
// let openPath = getSoitaskFilesOfFulltaskOrError(store, taskname)
// .soitaskFsPath!;
// let doc = await vscode.workspace.openTextDocument(openPath);
// editor = await vscode.window.showTextDocument(doc);
// editor.revealRange(loc);
// editor.selection = new vscode.Selection(
// new vscode.Position(sample.span.startLine, 0),
// new vscode.Position(
// sample.span.startLine,
// editor.document.lineAt(sample.span.startLine).range.end.character
// )
// );
// }
src/fs/workspaceTracker/soitask.ts
View file @
dace3cd9
...
...
@@ -3,7 +3,6 @@ import * as vscode from "vscode";
import
*
as
path
from
"
path
"
;
import
*
as
fs
from
"
fs-extra
"
;
import
{
taskTreeResourceEntry
}
from
"
../../ui/sidebar/taskTreeView
"
;
import
{
State
}
from
"
../../state/state
"
;
import
{
getWorkspaceOrShowError
,
...
...
@@ -11,74 +10,6 @@ import {
}
from
"
../../state/storeHelper
"
;
import
{
executableFileEnding
}
from
"
../../util
"
;
export
function
fspathToTasknameStringOnly
(
workspace
:
string
,
fspath
:
string
):
string
{
return
path
.
relative
(
workspace
,
path
.
join
(
path
.
dirname
(
fspath
),
path
.
basename
(
fspath
,
path
.
extname
(
fspath
)))
);
}
export
async
function
listSoitasks
(
workspace
:
string
):
Promise
<
Map
<
string
,
SoitaskFiles
>>
{
let
tasks
:
Map
<
string
,
SoitaskFiles
>
=
new
Map
();
let
cppFiles
=
await
vscode
.
workspace
.
findFiles
(
"
**/*.cpp
"
);
let
soitaskFiles
=
await
vscode
.
workspace
.
findFiles
(
"
**/*.soitask
"
);
let
tasknames
=
[];
let
cppTasknames
=
new
Map
<
string
,
string
>
();
let
soitaskTasknames
=
new
Map
<
string
,
string
>
();
for
(
let
cppFile
of
cppFiles
)
{
let
taskname
=
fspathToTasknameStringOnly
(
workspace
,
cppFile
.
fsPath
);
tasknames
.
push
(
taskname
);
cppTasknames
.
set
(
taskname
,
cppFile
.
fsPath
);
}
for
(
let
soitaskFile
of
soitaskFiles
)
{
let
taskname
=
fspathToTasknameStringOnly
(
workspace
,
soitaskFile
.
fsPath
);
tasknames
.
push
(
taskname
);
soitaskTasknames
.
set
(
taskname
,
soitaskFile
.
fsPath
);
}
tasknames
=
Array
.
from
(
new
Set
(
tasknames
));
const
undefinedToNullMapString
=
function
(
a
:
undefined
|
string
):
string
|
null
{
return
a
===
undefined
?
null
:
a
;
};
const
toRelativePath
=
function
(
a
:
undefined
|
string
):
string
|
null
{
return
a
===
undefined
?
null
:
path
.
join
(
path
.
relative
(
workspace
,
a
));
};
for
(
let
taskname
of
tasknames
)
{
tasks
.
set
(
taskname
,
{
taskname
:
taskname
,
solutionFsPath
:
undefinedToNullMapString
(
cppTasknames
.
get
(
taskname
)),
soitaskFsPath
:
undefinedToNullMapString
(
soitaskTasknames
.
get
(
taskname
)),
binaryFsPath
:
path
.
join
(
workspace
,
taskname
+
executableFileEnding
()),
solutionWorkspacePath
:
toRelativePath
(
cppTasknames
.
get
(
taskname
)),
soitaskWorkspacePath
:
toRelativePath
(
soitaskTasknames
.
get
(
taskname
)),
binaryWorkspacePath
:
taskname
+
executableFileEnding
()
});
}
return
tasks
;
}
export
function
fspathToTasknameOrError
(
store
:
State
,
fspath
:
string
):
string
{
if
(
path
.
extname
(
fspath
)
!==
"
.cpp
"
&&
path
.
extname
(
fspath
)
!==
"
.soitask
"
&&
path
.
extname
(
fspath
)
!==
""
)
{
throw
new
Error
(
"
Extension needs to be .cpp or .soitask
"
);
}
return
path
.
relative
(
getWorkspaceOrShowError
(
store
).
workspaceDir
,
path
.
join
(
path
.
dirname
(
fspath
),
path
.
basename
(
fspath
,
path
.
extname
(
fspath
)))
);
}
export
async
function
createCppFile
(
store
:
State
,
taskname
:
string
)
{
taskname
=
path
.
basename
(
taskname
);
let
preExistingTask
=
getWorkspaceOrShowError
(
store
).
task
.
get
(
taskname
);
...
...
@@ -132,39 +63,3 @@ export async function createTask(store: State) {
await
createCppFile
(
store
,
taskname
);
await
createSoitaskFile
(
store
,
taskname
);
}
async
function
selectTask
(
store
:
State
):
Promise
<
string
>
{
let
task
=
await
vscode
.
window
.
showQuickPick
(
listFullTasksOrError
(
store
).
map
(
soitaskFiles
=>
soitaskFiles
.
taskname
),
{
canPickMany
:
false
,
placeHolder
:
"
mytask
"
}
);
if
(
task
===
undefined
)
{
vscode
.
window
.
showErrorMessage
(
"
No task has been selected
"
);
throw
new
Error
(
"
No task has been selected
"
);
}
return
task
;
}
export
async
function
selectTaskDefault
(
store
:
State
,
defaultTask
:
string
|
undefined
|
null
|
vscode
.
Uri
|
taskTreeResourceEntry
):
Promise
<
string
>
{
let
editor
=
vscode
.
window
.
activeTextEditor
;
if
(
defaultTask
===
undefined
||
defaultTask
===
null
)
{
if
(
editor
!==
undefined
)
{
try
{
return
fspathToTasknameOrError
(
store
,
editor
.
document
.
uri
.
fsPath
);
}
catch
(
err
)
{}
}
return
await
selectTask
(
store
);
}
else
if
(
defaultTask
instanceof
vscode
.
Uri
)
{
return
fspathToTasknameOrError
(
store
,
defaultTask
.
fsPath
);
}
else
if
(
typeof
defaultTask
===
"
string
"
)
{
return
defaultTask
;
}
else
{
return
defaultTask
.
taskname
;
}
}
src/fs/workspaceTracker/soiworkspace.ts
View file @
dace3cd9
...
...
@@ -11,127 +11,6 @@ import {
}
from
"
../../input/compat/soiworkspaceFormats/soiworkspace-0-8-0
"
;
export
const
emptyWorkspaceState
:
WorkspaceState
=
"
NoFolderOpen
"
;
async
function
determineWorkspaceFolder
():
Promise
<
string
|
null
>
{
let
dirs
=
vscode
.
workspace
.
workspaceFolders
;
if
(
dirs
===
undefined
||
dirs
.
length
<=
0
)
{
let
response
=
await
vscode
.
window
.
showErrorMessage
(
"
There needs to be a open workspace
"
,
"
Open folder
"
,
"
Cancel
"
);
if
(
response
===
"
Open folder
"
)
{
await
vscode
.
commands
.
executeCommand
(
"
workbench.action.files.openLocalFolder
"
);
}
return
null
;
}
if
(
dirs
.
length
>
1
)
{
let
response
=
await
vscode
.
window
.
showErrorMessage
(
"
Multiroot workspaces are not supported
"
,
"
Open one folder
"
,
"
Cancel
"
);
if
(
response
===
"
Open one folder
"
)
{
await
vscode
.
commands
.
executeCommand
(
"
workbench.action.files.openLocalFolder
"
);
}
return
null
;
}
return
dirs
[
0
].
uri
.
fsPath
;
}
async
function
determineWorkspaceSettingsFileContent
(
store
:
State
,
workspace
:
string
):
Promise
<
string
|
null
>
{
let
workspaceSettings
=
await
vscode
.
workspace
.
findFiles
(
"
soiworkspace.json
"
);
if
(
workspaceSettings
.
length
>=
2
||
workspaceSettings
.
length
<
0
||
workspaceSettings
.
length
===
undefined
)
{
// Todo: Replace with assert
throw
new
Error
(
"
This is impossible
"
);
}
if
(
workspaceSettings
.
length
===
0
)
{
let
answer
=
await
vscode
.
window
.
showErrorMessage
(
"
There needs to be an initialized workspace
"
,
"
Initialize now
"
,
"
Cancel
"
);
if
(
answer
===
"
Initialize now
"
)
{
try
{
await
fs
.
writeFile
(
path
.
join
(
workspace
,
"
soiworkspace.json
"
),
soiWorkspaceTemplate_0_8_0
(
store
)
);
}
catch
(
err
)
{
vscode
.
window
.
showErrorMessage
(
"
Error initializing workspace:
"
+
err
.
toString
()
);
return
null
;
}
}
else
{
return
null
;
}
}
try
{
return
(
await
fs
.
readFile
(
path
.
join
(
workspace
,
"
soiworkspace.json
"
))
).
toString
();
}
catch
(
err
)
{
vscode
.
window
.
showErrorMessage
(
"
Cannot read soi workspace settings file:
"
+
err
.
toString
()
);
return
null
;
}
}
async
function
determineWorkspaceSettings
(
store
:
State
,
workspace
:
string
):
Promise
<
WorkspaceSettings
|
null
>
{
let
workspaceSettingsFileContent
=
await
determineWorkspaceSettingsFileContent
(
store
,
workspace
);
if
(
workspaceSettingsFileContent
===
null
)
{
return
null
;
}
try
{
return
checkIsWorkspaceSettings
(
JSON
.
parse
(
workspaceSettingsFileContent
.
toString
())
);
}
catch
(
e
)
{
vscode
.
window
.
showErrorMessage
(
"
Cannot parse workspace settings file:
"
+
e
.
toString
()
);
return
null
;
}
}
export
async
function
readWorkspaceState
(
store
:
State
):
Promise
<
WorkspaceState
>
{
let
workdir
=
await
determineWorkspaceFolder
();
if
(
workdir
===
null
)
{
return
"
NoFolderOpen
"
;
}
let
settings
=
await
determineWorkspaceSettings
(
store
,
workdir
);
if
(
settings
===
null
)
{
return
"
NoSOIWorkspace
"
;
}
let
tasks
=
await
listSoitasks
(
workdir
);
return
{
settings
:
settings
,
task
:
tasks
,
workspaceDir
:
workdir
};
}
export
async
function
initializeWorkspace
(
store
:
State
)
{
let
workspace
=
await
determineWorkspaceFolder
();
if
(
workspace
!==
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment