mirror of https://github.com/buggins/dlangide.git
clear code, add a unittest
This commit is contained in:
parent
6a338007db
commit
f3e69dccdd
|
@ -44,9 +44,8 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener {
|
||||||
//setTokenHightlightColor(TokenCategory.Identifier, 0x206000); // no colors
|
//setTokenHightlightColor(TokenCategory.Identifier, 0x206000); // no colors
|
||||||
MenuItem editPopupItem = new MenuItem(null);
|
MenuItem editPopupItem = new MenuItem(null);
|
||||||
editPopupItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_EDIT_UNDO,
|
editPopupItem.add(ACTION_EDIT_COPY, ACTION_EDIT_PASTE, ACTION_EDIT_CUT, ACTION_EDIT_UNDO,
|
||||||
ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT, ACTION_GET_COMPLETIONS,
|
ACTION_EDIT_REDO, ACTION_EDIT_INDENT, ACTION_EDIT_UNINDENT, ACTION_EDIT_TOGGLE_LINE_COMMENT,
|
||||||
ACTION_GO_TO_DEFINITION, ACTION_DEBUG_TOGGLE_BREAKPOINT);
|
ACTION_GET_COMPLETIONS, ACTION_GO_TO_DEFINITION, ACTION_DEBUG_TOGGLE_BREAKPOINT);
|
||||||
//ACTION_GO_TO_DEFINITION, ACTION_GET_COMPLETIONS
|
|
||||||
popupMenu = editPopupItem;
|
popupMenu = editPopupItem;
|
||||||
showIcons = true;
|
showIcons = true;
|
||||||
//showFolding = true;
|
//showFolding = true;
|
||||||
|
@ -107,7 +106,8 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@property bool isDSourceFile() {
|
@property bool isDSourceFile() {
|
||||||
return filename.endsWith(".d") || filename.endsWith(".dd") || filename.endsWith(".dd") || filename.endsWith(".di") || filename.endsWith(".dh") || filename.endsWith(".ddoc");
|
return filename.endsWith(".d") || filename.endsWith(".dd") || filename.endsWith(".dd") ||
|
||||||
|
filename.endsWith(".di") || filename.endsWith(".dh") || filename.endsWith(".ddoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
@property bool isJsonFile() {
|
@property bool isJsonFile() {
|
||||||
|
@ -528,7 +528,9 @@ class DSourceEdit : SourceEdit, EditableContentMarksChangeListener {
|
||||||
popupMenu.maxHeight(400);
|
popupMenu.maxHeight(400);
|
||||||
popupMenu.selectItem(0);
|
popupMenu.selectItem(0);
|
||||||
|
|
||||||
PopupWidget popup = window.showPopup(popupMenu, this, PopupAlign.Point | PopupAlign.Right, textPosToClient(_caretPos).left + left + _leftPaneWidth, textPosToClient(_caretPos).top + top + margins.top);
|
PopupWidget popup = window.showPopup(popupMenu, this, PopupAlign.Point | PopupAlign.Right,
|
||||||
|
textPosToClient(_caretPos).left + left + _leftPaneWidth,
|
||||||
|
textPosToClient(_caretPos).top + top + margins.top);
|
||||||
popup.setFocus();
|
popup.setFocus();
|
||||||
popup.popupClosed = delegate(PopupWidget source) { setFocus(); };
|
popup.popupClosed = delegate(PopupWidget source) { setFocus(); };
|
||||||
popup.flags = PopupFlags.CloseOnClickOutside;
|
popup.flags = PopupFlags.CloseOnClickOutside;
|
||||||
|
|
|
@ -18,10 +18,10 @@ import dlangide.workspace.workspace;
|
||||||
import dlangide.ui.commands;
|
import dlangide.ui.commands;
|
||||||
import dlangide.ui.frame;
|
import dlangide.ui.frame;
|
||||||
|
|
||||||
import std.path;
|
|
||||||
import std.file;
|
|
||||||
import std.array : empty;
|
|
||||||
import std.algorithm : startsWith, endsWith;
|
import std.algorithm : startsWith, endsWith;
|
||||||
|
import std.array : empty;
|
||||||
|
import std.file;
|
||||||
|
import std.path;
|
||||||
|
|
||||||
class FileCreationResult {
|
class FileCreationResult {
|
||||||
Project project;
|
Project project;
|
||||||
|
|
|
@ -5,19 +5,19 @@ import dlangide.workspace.projectsettings;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
import dlangui.core.collections;
|
import dlangui.core.collections;
|
||||||
import dlangui.core.settings;
|
import dlangui.core.settings;
|
||||||
import std.path;
|
|
||||||
import std.file;
|
|
||||||
import std.utf;
|
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
import std.array : empty;
|
||||||
|
import std.file;
|
||||||
|
import std.path;
|
||||||
import std.process;
|
import std.process;
|
||||||
import std.array;
|
import std.utf;
|
||||||
|
|
||||||
/// return true if filename matches rules for workspace file names
|
/// return true if filename matches rules for workspace file names
|
||||||
bool isProjectFile(string filename) {
|
bool isProjectFile(in string filename) pure nothrow {
|
||||||
return filename.baseName.equal("dub.json") || filename.baseName.equal("package.json");
|
return filename.baseName.equal("dub.json") || filename.baseName.equal("package.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
string toForwardSlashSeparator(string filename) {
|
string toForwardSlashSeparator(in string filename) pure nothrow {
|
||||||
char[] res;
|
char[] res;
|
||||||
foreach(ch; filename) {
|
foreach(ch; filename) {
|
||||||
if (ch == '\\')
|
if (ch == '\\')
|
||||||
|
@ -43,42 +43,26 @@ class ProjectItem {
|
||||||
this() {
|
this() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@property ProjectItem parent() {
|
@property ProjectItem parent() { return _parent; }
|
||||||
return _parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property Project project() {
|
@property Project project() { return _project; }
|
||||||
return _project;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property void project(Project p) {
|
@property void project(Project p) { _project = p; }
|
||||||
_project = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string filename() {
|
@property string filename() { return _filename; }
|
||||||
return _filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property dstring name() {
|
@property dstring name() { return _name; }
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string name8() {
|
@property string name8() {
|
||||||
return _name.toUTF8;
|
return _name.toUTF8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns true if item is folder
|
/// returns true if item is folder
|
||||||
@property const bool isFolder() {
|
@property const bool isFolder() { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/// returns child object count
|
/// returns child object count
|
||||||
@property int childCount() {
|
@property int childCount() { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/// returns child item by index
|
/// returns child item by index
|
||||||
ProjectItem child(int index) {
|
ProjectItem child(int index) { return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void refresh() {
|
void refresh() {
|
||||||
}
|
}
|
||||||
|
@ -171,7 +155,7 @@ class ProjectFolder : ProjectItem {
|
||||||
existing.loadItems();
|
existing.loadItems();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ProjectFolder dir = new ProjectFolder(src);
|
auto dir = new ProjectFolder(src);
|
||||||
addChild(dir);
|
addChild(dir);
|
||||||
Log.d(" added project folder ", src);
|
Log.d(" added project folder ", src);
|
||||||
dir.loadItems();
|
dir.loadItems();
|
||||||
|
@ -186,7 +170,7 @@ class ProjectFolder : ProjectItem {
|
||||||
ProjectItem existing = childByPathName(src);
|
ProjectItem existing = childByPathName(src);
|
||||||
if (existing)
|
if (existing)
|
||||||
return true;
|
return true;
|
||||||
ProjectSourceFile f = new ProjectSourceFile(src);
|
auto f = new ProjectSourceFile(src);
|
||||||
addChild(f);
|
addChild(f);
|
||||||
Log.d(" added project file ", src);
|
Log.d(" added project file ", src);
|
||||||
return true;
|
return true;
|
||||||
|
@ -253,14 +237,10 @@ class WorkspaceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// file name of workspace item
|
/// file name of workspace item
|
||||||
@property string filename() {
|
@property string filename() { return _filename; }
|
||||||
return _filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// workspace item directory
|
/// workspace item directory
|
||||||
@property string dir() {
|
@property string dir() { return _dir; }
|
||||||
return _dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// file name of workspace item
|
/// file name of workspace item
|
||||||
@property void filename(string fname) {
|
@property void filename(string fname) {
|
||||||
|
@ -274,28 +254,19 @@ class WorkspaceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// name
|
/// name
|
||||||
@property dstring name() {
|
@property dstring name() { return _name; }
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string name8() {
|
@property string name8() {
|
||||||
return _name.toUTF8;
|
return _name.toUTF8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// name
|
/// name
|
||||||
@property void name(dstring s) {
|
@property void name(dstring s) { _name = s; }
|
||||||
_name = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// name
|
/// description
|
||||||
@property dstring description() {
|
@property dstring description() { return _description; }
|
||||||
return _description;
|
/// description
|
||||||
}
|
@property void description(dstring s) { _description = s; }
|
||||||
|
|
||||||
/// name
|
|
||||||
@property void description(dstring s) {
|
|
||||||
_description = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// load
|
/// load
|
||||||
bool load(string fname) {
|
bool load(string fname) {
|
||||||
|
@ -465,14 +436,7 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
private static void addUnique(ref string[] dst, string[] items) {
|
private static void addUnique(ref string[] dst, string[] items) {
|
||||||
foreach(item; items) {
|
foreach(item; items) {
|
||||||
bool found = false;
|
if (!canFind(dst, item))
|
||||||
foreach(existing; dst) {
|
|
||||||
if (item.equal(existing)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
dst ~= item;
|
dst ~= item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,17 +463,11 @@ class Project : WorkspaceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@property ProjectSourceFile mainSourceFile() { return _mainSourceFile; }
|
@property ProjectSourceFile mainSourceFile() { return _mainSourceFile; }
|
||||||
@property ProjectFolder items() {
|
@property ProjectFolder items() { return _items; }
|
||||||
return _items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property Workspace workspace() {
|
@property Workspace workspace() { return _workspace; }
|
||||||
return _workspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property void workspace(Workspace p) {
|
@property void workspace(Workspace p) { _workspace = p; }
|
||||||
_workspace = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property string defWorkspaceFile() {
|
@property string defWorkspaceFile() {
|
||||||
return buildNormalizedPath(_filename.dirName, toUTF8(name) ~ WORKSPACE_EXTENSION);
|
return buildNormalizedPath(_filename.dirName, toUTF8(name) ~ WORKSPACE_EXTENSION);
|
||||||
|
@ -553,7 +511,7 @@ class Project : WorkspaceItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectFolder findItems(string[] srcPaths) {
|
ProjectFolder findItems(string[] srcPaths) {
|
||||||
ProjectFolder folder = new ProjectFolder(_filename);
|
auto folder = new ProjectFolder(_filename);
|
||||||
folder.project = this;
|
folder.project = this;
|
||||||
string path = relativeToAbsolutePath("src");
|
string path = relativeToAbsolutePath("src");
|
||||||
if (folder.loadDir(path))
|
if (folder.loadDir(path))
|
||||||
|
@ -594,14 +552,14 @@ class Project : WorkspaceItem {
|
||||||
|
|
||||||
/// tries to find source file in project, returns found project source file item, or null if not found
|
/// tries to find source file in project, returns found project source file item, or null if not found
|
||||||
ProjectSourceFile findSourceFileItem(ProjectItem dir, string filename, bool fullFileName=true) {
|
ProjectSourceFile findSourceFileItem(ProjectItem dir, string filename, bool fullFileName=true) {
|
||||||
for (int i = 0; i < dir.childCount; i++) {
|
foreach(i; 0 .. dir.childCount) {
|
||||||
ProjectItem item = dir.child(i);
|
ProjectItem item = dir.child(i);
|
||||||
if (item.isFolder) {
|
if (item.isFolder) {
|
||||||
ProjectSourceFile res = findSourceFileItem(item, filename, fullFileName);
|
ProjectSourceFile res = findSourceFileItem(item, filename, fullFileName);
|
||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
ProjectSourceFile res = cast(ProjectSourceFile)item;
|
auto res = cast(ProjectSourceFile)item;
|
||||||
if(res)
|
if(res)
|
||||||
{
|
{
|
||||||
if(fullFileName && res.filename.equal(filename))
|
if(fullFileName && res.filename.equal(filename))
|
||||||
|
@ -680,7 +638,7 @@ class Project : WorkspaceItem {
|
||||||
bool loadSelections() {
|
bool loadSelections() {
|
||||||
Project[] newdeps;
|
Project[] newdeps;
|
||||||
_dependencies.length = 0;
|
_dependencies.length = 0;
|
||||||
DubPackageFinder finder = new DubPackageFinder();
|
auto finder = new DubPackageFinder;
|
||||||
scope(exit) destroy(finder);
|
scope(exit) destroy(finder);
|
||||||
SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json"));
|
SettingsFile selectionsFile = new SettingsFile(buildNormalizedPath(_dir, "dub.selections.json"));
|
||||||
if (!selectionsFile.load()) {
|
if (!selectionsFile.load()) {
|
||||||
|
@ -768,37 +726,46 @@ class DubPackageFinder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidProjectName(string s) {
|
bool isValidProjectName(in string s) pure {
|
||||||
if (s.empty)
|
if (s.empty)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < s.length; i++) {
|
return reduce!q{ a && (b == '_' || b == '-' || std.ascii.isAlphaNum(b)) }(true, s);
|
||||||
char ch = s[i];
|
|
||||||
if (ch != '_' && ch != '-' && (ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidModuleName(string s) {
|
bool isValidModuleName(in string s) pure {
|
||||||
if (s.empty)
|
if (s.empty)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < s.length; i++) {
|
return reduce!q{ a && (b == '_' || std.ascii.isAlphaNum(b)) }(true, s);
|
||||||
char ch = s[i];
|
|
||||||
if (ch != '_' && (ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidFileName(string s) {
|
bool isValidFileName(in string s) pure {
|
||||||
if (s.empty)
|
if (s.empty)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < s.length; i++) {
|
return reduce!q{ a && (b == '_' || b == '.' || b == '-' || std.ascii.isAlphaNum(b)) }(true, s);
|
||||||
char ch = s[i];
|
|
||||||
if (ch != '_' && ch != '.' && ch != '-' && (ch < '0' || ch > '9') && (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
unittest {
|
||||||
|
assert(!isValidProjectName(""));
|
||||||
|
assert(isValidProjectName("project"));
|
||||||
|
assert(isValidProjectName("cool_project"));
|
||||||
|
assert(isValidProjectName("project-2"));
|
||||||
|
assert(!isValidProjectName("project.png"));
|
||||||
|
assert(!isValidProjectName("[project]"));
|
||||||
|
assert(!isValidProjectName("<project/>"));
|
||||||
|
assert(!isValidModuleName(""));
|
||||||
|
assert(isValidModuleName("module"));
|
||||||
|
assert(isValidModuleName("awesome_module2"));
|
||||||
|
assert(!isValidModuleName("module-2"));
|
||||||
|
assert(!isValidModuleName("module.png"));
|
||||||
|
assert(!isValidModuleName("[module]"));
|
||||||
|
assert(!isValidModuleName("<module>"));
|
||||||
|
assert(!isValidFileName(""));
|
||||||
|
assert(isValidFileName("file"));
|
||||||
|
assert(isValidFileName("file_2"));
|
||||||
|
assert(isValidFileName("file-2"));
|
||||||
|
assert(isValidFileName("file.txt"));
|
||||||
|
assert(!isValidFileName("[file]"));
|
||||||
|
assert(!isValidFileName("<file>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
class EditorBookmark {
|
class EditorBookmark {
|
||||||
|
|
|
@ -5,12 +5,12 @@ import dlangide.workspace.workspacesettings;
|
||||||
import dlangide.ui.frame;
|
import dlangide.ui.frame;
|
||||||
import dlangui.core.logger;
|
import dlangui.core.logger;
|
||||||
import dlangui.core.settings;
|
import dlangui.core.settings;
|
||||||
|
import std.algorithm : map;
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.path;
|
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.range;
|
import std.path;
|
||||||
|
import std.range : array;
|
||||||
import std.utf;
|
import std.utf;
|
||||||
import std.algorithm;
|
|
||||||
|
|
||||||
import ddebug.common.debugger;
|
import ddebug.common.debugger;
|
||||||
|
|
||||||
|
@ -75,9 +75,7 @@ class Workspace : WorkspaceItem {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property Project[] projects() {
|
@property Project[] projects() { return _projects; }
|
||||||
return _projects;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property BuildConfiguration buildConfiguration() { return _buildConfiguration; }
|
@property BuildConfiguration buildConfiguration() { return _buildConfiguration; }
|
||||||
@property void buildConfiguration(BuildConfiguration config) { _buildConfiguration = config; }
|
@property void buildConfiguration(BuildConfiguration config) { _buildConfiguration = config; }
|
||||||
|
|
Loading…
Reference in New Issue