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
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@
"command": "second-life-scripting.forceLanguageUpdate",
"title": "Force Language Update",
"category": "Second Life"
},
{
"command": "second-life-scripting.stopFileSync",
"shortTitle": "Stop File Sync",
"title": "Stop file sync with SL Viewer",
"category": "Second Life"
}
],
"menus": {
"explorer/context": [
{
"command": "second-life-scripting.stopFileSync",
"group": "navigation@99",
"when": "resourceScheme == file && slVscodeEdit:syncsActive"
}
],
"editor/title/context": [
{
"command": "second-life-scripting.stopFileSync",
"group": "1_close@99",
"when": "resourceScheme == file && slVscodeEdit:syncsActive"
}
]
},
"colors": [
{
"id": "secondlife.syncedfile",
"description": "Color for files that are being synced with the viewer",
"defaults": {
"dark": "tab.activeBorderTop",
"light": "tab.activeBorderTop",
"highContrast": "tab.activeBorderTop",
"highContrastLight": "tab.activeBorderTop"
Comment thread
WolfGangS marked this conversation as resolved.
}
}
],
"configuration": [
Expand Down Expand Up @@ -106,6 +140,11 @@
"default": false,
"description": "Whether the current sl user info should be included in the meta info"
},
"slVscodeEdit.sync.keepViewerFileOpen": {
"type": "boolean",
"default": true,
"description": "Should the viewers tempfile be kept open while editing"
},
"slVscodeEdit.sync.notecardComment": {
"type": "string",
"default" : null,
Expand Down
67 changes: 43 additions & 24 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
showErrorMessage
} from "./utils";
import { ConfigKey } from "./interfaces/configinterface";
import path from "path";

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand All @@ -34,7 +35,35 @@ export function activate(context: vscode.ExtensionContext): void {
showErrorMessage("Second Life Scripting Extension: No workspace is opened.\nPlease open a folder in VSCode to enable full functionality.");
}

setupCommands(context);

configService.on(ConfigKey.Enabled, (configService) => {
if(configService.isEnabled()) {
synchService.activate();
logInfo("Second Life Scripting Extension activated");
} else {
synchService.deactivate();
logInfo("Second Life Scripting Extension deactivated");
}
});

if(configService.isEnabled()) {
synchService.activate();
logInfo("Second Life Scripting Extension activated");
}

context.subscriptions.push(configService);
context.subscriptions.push(languageService);
context.subscriptions.push(synchService);
}

// This method is called when your extension is deactivated
export function deactivate(): void {
const synchService = SynchService.getInstance();
synchService.deactivate();
}

function setupCommands(context: vscode.ExtensionContext) : void {
// Register commands
context.subscriptions.push(
vscode.commands.registerCommand(
Expand Down Expand Up @@ -89,28 +118,18 @@ export function activate(context: vscode.ExtensionContext): void {
)
);

configService.on(ConfigKey.Enabled, (configService) => {
if(configService.isEnabled()) {
synchService.activate();
logInfo("Second Life Scripting Extension activated");
} else {
synchService.deactivate();
logInfo("Second Life Scripting Extension deactivated");
}
});

if(configService.isEnabled()) {
synchService.activate();
logInfo("Second Life Scripting Extension activated");
}

context.subscriptions.push(configService);
context.subscriptions.push(languageService);
context.subscriptions.push(synchService);
}

// This method is called when your extension is deactivated
export function deactivate(): void {
const synchService = SynchService.getInstance();
synchService.deactivate();
context.subscriptions.push(
vscode.commands.registerCommand(
"second-life-scripting.stopFileSync",
(uri?: vscode.Uri) => {
if(!uri) {
uri = vscode.window.activeTextEditor?.document.uri;
}
if(!uri) {
return;
}
SynchService.getInstance().removeSync(path.normalize(uri.fsPath));
}
)
);
}
1 change: 1 addition & 0 deletions src/interfaces/configinterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum ConfigKey {
LastSyntaxID = 'syntax.lastID',
AskIfViewerScriptMismatchesMaster = 'sync.askIfViewerScriptMismatchesMaster',
CompareHashBeforeSync = 'sync.compareHashBeforeSync',
KeepViewerFileOpen = 'sync.keepViewerFileOpen',
NotecardSyncComment = 'sync.notecardComment',

FileMetaInfoInOutput ='sync.includeFileMetaInOutput',
Expand Down
29 changes: 18 additions & 11 deletions src/scriptsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "./utils";
import { ScriptLanguage } from "./shared/languageservice";
import { CompilationResult, RuntimeDebug, RuntimeError } from "./viewereditwsclient";
import { HostInterface, normalizePath } from "./interfaces/hostinterface";
import { normalizePath } from "./interfaces/hostinterface";
import { SynchService } from "./synchservice";
import { IncludeInfo } from "./shared/parser";
import { sha256 } from "js-sha256";
Expand All @@ -51,18 +51,19 @@ export class ScriptSync implements vscode.Disposable {
private diagnosticSources: Set<string> = new Set();
private lineMappings?: LineMapping[];
private config: ConfigService;
private host: HostInterface;
// private host: HostInterface;

private includedFiles : IncludeInfo[] = [];
private syncService: SynchService;

//====================================================================
public constructor(
masterDocument: vscode.TextDocument,
language: ScriptLanguage,
config: ConfigService,
scriptId?: string,
viewerDocument?: vscode.TextDocument,
host?: HostInterface,
scriptId: string,
viewerDocument: vscode.TextDocument,
syncService: SynchService,
) {
this.config = config;

Expand All @@ -71,12 +72,12 @@ export class ScriptSync implements vscode.Disposable {
this.macros = new MacroProcessor();
this.initializeSystemMacros(language);

this.host = host ?? new VSCodeHost();
this.syncService = syncService;

// Initialize preprocessor with macro processor
const enabled = config.getConfig<boolean>(ConfigKey.PreprocessorEnable, true);
if (enabled && isProccessedLanguage(this.language)) {
this.preprocessor = new LexingPreprocessor(this.host, config, this.macros);
this.preprocessor = new LexingPreprocessor(this.syncService.getHost(), config, this.macros);
}

this.masterDocument = masterDocument;
Expand Down Expand Up @@ -146,6 +147,10 @@ export class ScriptSync implements vscode.Disposable {
this.fileMappings = this.fileMappings.filter((m) => m !== mapping);
if (close) {
closeTextDocument(mapping.viewerDocument);
mapping.watcher?.dispose();
}
if(!this.hasFilesToTrack()) {
this.syncService.clearEmptySyncs();
}
}
return this.fileMappings.length;
Expand All @@ -157,10 +162,7 @@ export class ScriptSync implements vscode.Disposable {
(m) => path.normalize(m.viewerDocument.fileName) === viewerFile,
);
if (mapping) {
this.fileMappings = this.fileMappings.filter((m) => m !== mapping);
if (close) {
closeTextDocument(mapping.viewerDocument);
}
this.unsubscribeById(mapping.id, close);
}
return this.fileMappings.length;
}
Expand All @@ -178,6 +180,10 @@ export class ScriptSync implements vscode.Disposable {
);
}

public hasFilesToTrack() : boolean {
return this.fileMappings.length > 0;
}

public getMasterDocument(): vscode.TextDocument {
return this.masterDocument;
}
Expand Down Expand Up @@ -585,6 +591,7 @@ export class ScriptSync implements vscode.Disposable {

try {
this.diagnosticCollection.dispose();
this.fileMappings.forEach(map => map.watcher?.dispose());
} catch (error) {
// Log but don't throw during disposal
console.warn("Error during ScriptSync disposal:", error);
Expand Down
Loading
Loading