Skip to content
Open
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
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `autoit.maps.includeDepth` - Maximum depth for resolving #include files (default: 3, range: 0-10)
- `autoit.maps.showFunctionKeys` - Show Map keys assigned in functions (default: true)
- See [docs/map-support.md](docs/map-support.md) for performance tuning recommendations
- Ignore AutoIt Tidy backup files from diagnostics

### Changed

- Enhanced README documentation with Map intelligence feature details

### Refactored

- Extract and enhance formatter constants into constants.js file

## [1.3.0] - 2025-11-10

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/ai_completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
setRegExpFlags,
variablePattern,
} from './util';
import DEFAULT_UDFS from './constants';
import { DEFAULT_UDFS } from './constants';
import MapTrackingService from './services/MapTrackingService.js';

// Per-document cache for include completions
Expand Down
20 changes: 6 additions & 14 deletions src/ai_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ import fs from 'fs/promises';
import fsSync from 'fs';
import path from 'path';
import conf from './ai_config';

// Constants for configuration and file operations
const FORMATTER_CONSTANTS = {
TEMP_FILE_PREFIX: 'temp_format_',
BACKUP_DIR_NAME: 'Backup',
BACKUP_SUFFIX: '_old1.au3',
TIDY_TIMEOUT_MS: 10000, // Increased timeout for better reliability
FILE_EXTENSION: '.au3',
};
import { FORMATTER } from './constants';

/**
* AutoIt document formatter provider that integrates with AutoIt3Wrapper Tidy
Expand Down Expand Up @@ -45,7 +37,7 @@ const AutoItFormatterProvider = {
}

const tempFile = generateTempFilePath(workspaceFolder);
const backupDir = path.join(workspaceFolder, FORMATTER_CONSTANTS.BACKUP_DIR_NAME);
const backupDir = path.join(workspaceFolder, FORMATTER.BACKUP_DIR_NAME);

console.log(`[AutoIt Formatter] Workspace: ${workspaceFolder}`);
console.log(`[AutoIt Formatter] Temp file: ${tempFile}`);
Expand Down Expand Up @@ -157,9 +149,9 @@ async function runTidy(filePath) {
if (!hasExited && !tidyProcess.killed) {
hasExited = true;
tidyProcess.kill('SIGTERM'); // Use SIGTERM for graceful shutdown
reject(new Error(`Tidy process timed out after ${FORMATTER_CONSTANTS.TIDY_TIMEOUT_MS}ms`));
reject(new Error(`Tidy process timed out after ${FORMATTER.TIDY_TIMEOUT_MS}ms`));
}
}, FORMATTER_CONSTANTS.TIDY_TIMEOUT_MS);
}, FORMATTER.TIDY_TIMEOUT_MS);

// Capture stdout and stderr
tidyProcess.stdout.on('data', data => {
Expand Down Expand Up @@ -221,7 +213,7 @@ async function runTidy(filePath) {
function generateTempFilePath(workspaceFolder) {
const timestamp = Date.now();
const randomSuffix = Math.random().toString(36).substring(2, 8);
const fileName = `${FORMATTER_CONSTANTS.TEMP_FILE_PREFIX}${timestamp}_${randomSuffix}${FORMATTER_CONSTANTS.FILE_EXTENSION}`;
const fileName = `${FORMATTER.TEMP_FILE_PREFIX}${timestamp}_${randomSuffix}${FORMATTER.FILE_EXTENSION}`;
return path.join(workspaceFolder, fileName);
}

Expand Down Expand Up @@ -258,7 +250,7 @@ async function cleanupFiles(tempFile, backupDir) {
// Clean up backup file if it exists
const backupFile = path.join(
backupDir,
path.basename(tempFile, FORMATTER_CONSTANTS.FILE_EXTENSION) + FORMATTER_CONSTANTS.BACKUP_SUFFIX,
path.basename(tempFile, FORMATTER.FILE_EXTENSION) + FORMATTER.BACKUP_FILE_SUFFIX,
);
cleanupPromises.push(
safeDeleteFile(backupFile).catch(error =>
Expand Down
2 changes: 1 addition & 1 deletion src/ai_signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
libraryIncludePattern,
} from './util';
import defaultSigs from './signatures';
import DEFAULT_UDFS from './constants';
import { DEFAULT_UDFS } from './constants';

let currentIncludeFiles = [];
let includes = {};
Expand Down
14 changes: 13 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,16 @@ const DEFAULT_UDFS = [
'WordConstants',
];

export default DEFAULT_UDFS;
/**
* Formatter constants for AutoIt Tidy and backup operations
*/
const FORMATTER = {
TEMP_FILE_PREFIX: 'temp_format_',
BACKUP_DIR_NAME: 'BackUp',
BACKUP_FILE_SUFFIX: '_old1.au3',
BACKUP_FILE_SUFFIX_PATTERN: /_old\d*\.au3$/i,
TIDY_TIMEOUT_MS: 10000, // Increased timeout for better reliability
FILE_EXTENSION: '.au3',
};

export { DEFAULT_UDFS, FORMATTER };
31 changes: 30 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { languages, window, workspace } from 'vscode';
import { dirname } from 'path';
import { basename, dirname, sep } from 'path';
import { existsSync } from 'fs';
import { execFile } from 'child_process';
import { FORMATTER } from './constants';
import languageConfiguration from './languageConfiguration';
import hoverFeature from './ai_hover';
import completionFeature from './ai_completion';
Expand Down Expand Up @@ -131,6 +132,28 @@ const validateFormatterPaths = () => {
return true;
};

/**
* Checks if a document should be ignored by diagnostics (AutoIt Tidy backup files)
* @param {import('vscode').TextDocument} document - Document to check
* @returns {boolean} True if document should be ignored
*/
const shouldIgnoreDiagnostics = document => {
const filePath = document.uri.fsPath;
const fileName = basename(filePath);

// Ignore files in "BackUp" folder
if (filePath.includes(sep + FORMATTER.BACKUP_DIR_NAME + sep)) {
return true;
}

// Ignore *_old*.au3 files
if (FORMATTER.BACKUP_FILE_SUFFIX_PATTERN.test(fileName)) {
return true;
}

return false;
};

/**
* Checks the AutoIt code in the given document and updates the diagnostic collection.
* @param {import('vscode').TextDocument} document - The document to check.
Expand All @@ -144,6 +167,12 @@ const checkAutoItCode = async (document, diagnosticCollection) => {

if (document.languageId !== 'autoit') return;

// Ignore backup files from AutoIt Tidy
if (shouldIgnoreDiagnostics(document)) {
diagnosticCollection.delete(document.uri);
return;
}

const { checkPath } = config;
if (!validateCheckPath(checkPath)) return;

Expand Down