Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/syntax_def_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -18590,4 +18590,4 @@
],
"version": "1.0.0"
}
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
{
"title": "SL Scripting - Sync",
"properties": {
"slVscodeEdit.sync.askIfViewerScriptMismatchesMaster": {
"type": "boolean",
"default": true,
"description": "Should the plugin ask what to do if viewer file and master file have differences? You probably want to disable this if you use the proprocessor or require()"
},
"slVscodeEdit.sync.compareHashBeforeSync": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/configinterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum ConfigKey {
PreprocessorMaxIncludeDepth = 'preprocessor.maxIncludeDepth',
PreprocessorConstantsInSLua = 'preprocessor.constantsInSLua',
LastSyntaxID = 'syntax.lastID',
AskIfViewerScriptMismatchesMaster = 'sync.askIfViewerScriptMismatchesMaster',
CompareHashBeforeSync = 'sync.compareHashBeforeSync',

FileMetaInfoInOutput ='sync.includeFileMetaInOutput',
Expand Down
4 changes: 2 additions & 2 deletions src/shared/luadefsgenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class LuauDefsGenerator {
// Split classes into those that depend on type aliases and those that don't
const baseClasses: ClassDeclaration[] = [];
const dependentClasses: ClassDeclaration[] = [];

if (defs.classes && defs.classes.length > 0) {
for (const cls of defs.classes) {
if (this.classUsesTypeAliases(cls)) {
Expand Down Expand Up @@ -305,7 +305,7 @@ export class LuauDefsGenerator {
}

lines.push('}');

return `${callSig} & ${lines.join('\n')}`;
}

Expand Down
34 changes: 30 additions & 4 deletions src/synchservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export class SynchService implements vscode.Disposable {
const masterPath = masterUri.fsPath;
// Open the master script file in the editor
showInfoMessage(`Opening master script: ${path.basename(masterPath)}`);
let masterDoc = await SynchService.openMasterScript(masterUri);
let masterEditor = await SynchService.openMasterScript(masterUri);
let masterDoc = masterEditor.document
SynchService.checkAndUpdateMasterDocumentInBackground(masterEditor, viewerDocument)

// Connection goes on in the background
let viewerConnecting: Promise<boolean> = this.setupConnection();
Expand Down Expand Up @@ -656,10 +658,34 @@ export class SynchService implements vscode.Disposable {

private static async openMasterScript(
masterUri: vscode.Uri,
): Promise<vscode.TextDocument> {
): Promise<vscode.TextEditor> {
const masterDoc = await vscode.workspace.openTextDocument(masterUri);
await vscode.window.showTextDocument(masterDoc, { preview: false });
return masterDoc;
return await vscode.window.showTextDocument(masterDoc, { preview: false });
}

private static checkAndUpdateMasterDocumentInBackground(masterEditor: vscode.TextEditor, viewerDocument: vscode.TextDocument): void {
if(!ConfigService.getInstance().getConfig<boolean>(ConfigKey.AskIfViewerScriptMismatchesMaster, true)) return;
if(masterEditor.document.getText() == viewerDocument.getText()) return;
const viewerFileName = SynchService.parseTempFile(viewerDocument.fileName)?.scriptName;
const masterFileName = path.basename(masterEditor.document.fileName);
vscode.window.showInformationMessage(`Viewer script "${viewerFileName}" differs from master script "${masterFileName}". What would you like to do?`,
"Ignore", "Overwrite master", "Compare", "Always ignore").then(async (pick) => {

if(pick === "Always ignore") {
ConfigService.getInstance().setConfig<boolean>(ConfigKey.AskIfViewerScriptMismatchesMaster, false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was what I was looking for. So, it will ask the first time, if I say "Always ignore" it will unset the config.

} else if(pick === "Overwrite master") {
const firstLine = masterEditor.document.lineAt(0);
const lastLine = masterEditor.document.lineAt(masterEditor.document.lineCount - 1);
const textRange = new vscode.Range(firstLine.range.start, lastLine.range.end);
masterEditor.edit(edit => edit.replace(textRange, viewerDocument.getText()));
} else if(pick === "Compare") {
const viewer = viewerDocument.uri;
const master = masterEditor.document.uri;
const title = `${viewerFileName} (Viewer) ↔ ${masterFileName} (Master)`;
await vscode.commands.executeCommand("vscode.diff", viewer, master, title); //, { preview: false });
}
})
//*/
}

public getWebSocket(): ViewerEditWSClient | undefined {
Expand Down
Loading