Skip to content

Handling of generated files #712

Open
@RalphGauer-Paul

Description

@RalphGauer-Paul

I searched for an option to make generated files in VSCode readonly.
My first attempt was to contact the maintainers of vscode-objectscript if there was an option to achieve this.
intersystems-community/vscode-objectscript#1478
The result of this discussion lead to a change I made to Extension.cls of the installed git-source-control version 2.9.0:

diff --git a/cls/SourceControl/Git/Extension.cls b/cls/SourceControl/Git/Extension.cls
index 69fdaaa..2a6fd66 100644
+++ b/cls/SourceControl/Git/Extension.cls
@@ -432,8 +432,39 @@ ClassMethod FullExternalName(InternalName As %String) As %String
     quit ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
 }
 
+ClassMethod IsGenerated(InternalName As %String) As %String
+{
+	Set name=##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName),nm=$piece(name,".",1,*-1)
+	If nm="" Quit 0
+	/* // would make a loop?
+	Set generated=##class(%Studio.SourceControl.Interface).IsGenerated(name)
+	If generated'="" Quit generated
+	*/
+	Set ext=$zconvert($piece(name,".",*),"U")
+	If ..IsCSPName(name) {
+		Quit 0
+	} ElseIf ext="CLS" {
+		Quit +$listget($get(^rINDEXCLASS($zconvert(nm,"U"))),10,0)
+	} ElseIf $$$rtnIsMAC(ext) {
+		Quit +$get(^rMAC(nm,0,"GENERATED"))
+	} ElseIf $$$rtnIsINT(ext) {
+		Quit +$get(^ROUTINE(nm,0,"GENERATED"))
+	} ElseIf $$$rtnIsINC(ext) {
+		Quit +$get(^rINC(nm,0,"GENERATED"))
+	} ElseIf ext="PRJ" {
+		Quit 0
+	} /*ElseIf ..UserType(name,.cls) {
+		Quit +$classmethod(cls,"IsGenerated",name)
+	} */
+	Quit 0
+}
+
+ClassMethod IsCSPName(name As %String) As %Boolean
+{
+	Quit $$IsCSPName^%occXMLExport(name)
+}
+
 Method IsReadOnly(InternalName As %String) As %Boolean
 {
+    quit:..IsGenerated(InternalName) 1
     set settings = ##class(SourceControl.Git.Settings).%New()
     quit (##class(SourceControl.Git.Utils).Locked() 
             && '$get(^IRIS.Temp("sscProd",$job,"bypassLock")))
@@ -507,7 +538,8 @@ Method GetStatus(ByRef InternalName As %String, ByRef IsInSourceControl As %Bool
         }
     } else {
         // If it doesn't show up in git status, there are no uncommitted changes so it should not be locked or checked out by any user
-        set Editable=1, IsCheckedOut=0, UserCheckedOut=""
+        //set Editable=1
+        set IsCheckedOut=0, UserCheckedOut=""
         if ##class(SourceControl.Git.Change).IsUncommitted(filename){
             #; Remove the item from the list of uncommitted changes;
             set sc=##class(SourceControl.Git.Change).RemoveUncommitted(filename,1,1)

Maybe this could be made an option just like "Treat Mapped Items as Read-only" in the settings of git-source-control
as an enhancement.
The "IsGenerated"/"IsCSPName" part is a modified excerpt of %Library.RoutineMgr.cls

Metadata

Metadata

Assignees

Labels

customerBased on customer feedback (as opposed to something identified by developers)good first issueGood for newcomers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions