fix: error cannot read 'charAt'
This commit is contained in:
parent
437bbf0c9d
commit
ef67a8107a
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,3 +2,5 @@ node_modules
|
||||||
*.vsix
|
*.vsix
|
||||||
/scrapper/discovered_mnemonics.txt
|
/scrapper/discovered_mnemonics.txt
|
||||||
/scrapper/mnemonic_url_mappings.txt
|
/scrapper/mnemonic_url_mappings.txt
|
||||||
|
*.s
|
||||||
|
*.asm
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "x86-assembly-syntax",
|
"name": "x86-assembly-syntax",
|
||||||
"displayName": "Universal Assembly Syntax Highlighting",
|
"displayName": "Universal Assembly Syntax Highlighting",
|
||||||
"description": "Syntax highlighting extension for x86, x64 and ARM assembly both for Intel and AT&T syntax",
|
"description": "Syntax highlighting extension for x86, x64 and ARM assembly both for Intel and AT&T syntax",
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.75.0"
|
"vscode": "^1.75.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
104
src/extension.js
104
src/extension.js
|
|
@ -2,32 +2,26 @@ const vscode = require("vscode");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
let languageConfigDisposable = null;
|
|
||||||
let instructionData = null;
|
let instructionData = null;
|
||||||
|
|
||||||
function activate(context) {
|
function activate(context) {
|
||||||
// Load instruction data from local JSON file
|
// Load instruction data from local JSON file
|
||||||
loadInstructionData();
|
loadInstructionData();
|
||||||
|
|
||||||
// Set up initial language configuration
|
|
||||||
updateLanguageConfiguration();
|
|
||||||
|
|
||||||
// Listen for configuration changes
|
|
||||||
const configChangeListener = vscode.workspace.onDidChangeConfiguration(
|
|
||||||
(event) => {
|
|
||||||
if (event.affectsConfiguration("assembly.comments")) {
|
|
||||||
updateLanguageConfiguration();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Hover provider for mnemonics
|
// Hover provider for mnemonics
|
||||||
const hoverProvider = vscode.languages.registerHoverProvider("x86asm", {
|
const hoverProvider = vscode.languages.registerHoverProvider("x86asm", {
|
||||||
provideHover(document, position, token) {
|
provideHover(document, position, token) {
|
||||||
|
try {
|
||||||
const range = document.getWordRangeAtPosition(
|
const range = document.getWordRangeAtPosition(
|
||||||
position,
|
position,
|
||||||
/\b[a-zA-Z0-9_]+\b/
|
/\b[a-zA-Z0-9_]+\b/
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Add null check for range to prevent charAt error
|
||||||
|
if (!range) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const word = document.getText(range);
|
const word = document.getText(range);
|
||||||
|
|
||||||
if (word && instructionData) {
|
if (word && instructionData) {
|
||||||
|
|
@ -39,6 +33,10 @@ function activate(context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in hover provider:", error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -47,6 +45,7 @@ function activate(context) {
|
||||||
"x86asm",
|
"x86asm",
|
||||||
{
|
{
|
||||||
async provideDefinition(document, position, token) {
|
async provideDefinition(document, position, token) {
|
||||||
|
try {
|
||||||
const range = document.getWordRangeAtPosition(position);
|
const range = document.getWordRangeAtPosition(position);
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -54,15 +53,15 @@ function activate(context) {
|
||||||
|
|
||||||
const word = document.getText(range);
|
const word = document.getText(range);
|
||||||
return await findDefinition(word);
|
return await findDefinition(word);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in definition provider:", error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(hoverProvider, definitionProvider);
|
||||||
hoverProvider,
|
|
||||||
definitionProvider,
|
|
||||||
configChangeListener
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadInstructionData() {
|
function loadInstructionData() {
|
||||||
|
|
@ -97,55 +96,8 @@ function loadInstructionData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateLanguageConfiguration() {
|
|
||||||
// Dispose previous language configuration if it exists
|
|
||||||
if (languageConfigDisposable) {
|
|
||||||
languageConfigDisposable.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current configuration
|
|
||||||
const config = vscode.workspace.getConfiguration("assembly.comments");
|
|
||||||
const lineComment = config.get("lineComment", ";");
|
|
||||||
const blockComment = config.get("blockComment", ["/*", "*/"]);
|
|
||||||
|
|
||||||
// Register new language configuration
|
|
||||||
languageConfigDisposable = vscode.languages.setLanguageConfiguration(
|
|
||||||
"x86asm",
|
|
||||||
{
|
|
||||||
comments: {
|
|
||||||
lineComment: lineComment,
|
|
||||||
blockComment: blockComment,
|
|
||||||
},
|
|
||||||
brackets: [
|
|
||||||
["{", "}"],
|
|
||||||
["[", "]"],
|
|
||||||
["(", ")"],
|
|
||||||
],
|
|
||||||
autoClosingPairs: [
|
|
||||||
["{", "}"],
|
|
||||||
["[", "]"],
|
|
||||||
["(", ")"],
|
|
||||||
['"', '"'],
|
|
||||||
["'", "'"],
|
|
||||||
],
|
|
||||||
surroundingPairs: [
|
|
||||||
["{", "}"],
|
|
||||||
["[", "]"],
|
|
||||||
["(", ")"],
|
|
||||||
['"', '"'],
|
|
||||||
["'", "'"],
|
|
||||||
],
|
|
||||||
folding: {
|
|
||||||
markers: {
|
|
||||||
start: "\\.section",
|
|
||||||
end: "\\.endsection",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getInstructionInfo(instruction) {
|
function getInstructionInfo(instruction) {
|
||||||
|
try {
|
||||||
if (!instructionData) {
|
if (!instructionData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -157,7 +109,7 @@ function getInstructionInfo(instruction) {
|
||||||
|
|
||||||
// Format the hover content using the syntaxes/x86_instructions.json format
|
// Format the hover content using the syntaxes/x86_instructions.json format
|
||||||
// Keep title as is since it usually doesn't need paragraph breaks
|
// Keep title as is since it usually doesn't need paragraph breaks
|
||||||
let hoverContent = `**${info.title}**\n\n`;
|
let hoverContent = `**${info.title || "Unknown Instruction"}**\n\n`;
|
||||||
|
|
||||||
if (info.opcode) {
|
if (info.opcode) {
|
||||||
hoverContent += `**Opcode:** ${info.opcode}\n\n`;
|
hoverContent += `**Opcode:** ${info.opcode}\n\n`;
|
||||||
|
|
@ -174,9 +126,14 @@ function getInstructionInfo(instruction) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return hoverContent;
|
return hoverContent;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in getInstructionInfo:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findDefinition(word) {
|
async function findDefinition(word) {
|
||||||
|
try {
|
||||||
// Get all x86 assembly files in the workspace
|
// Get all x86 assembly files in the workspace
|
||||||
const files = await vscode.workspace.findFiles(
|
const files = await vscode.workspace.findFiles(
|
||||||
"**/*.s",
|
"**/*.s",
|
||||||
|
|
@ -197,9 +154,14 @@ async function findDefinition(word) {
|
||||||
|
|
||||||
// If no definition is found, return undefined
|
// If no definition is found, return undefined
|
||||||
return undefined;
|
return undefined;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in findDefinition:", error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchForDefinition(lines, word, document) {
|
function searchForDefinition(lines, word, document) {
|
||||||
|
try {
|
||||||
const externRegex = new RegExp(`^extern\\s+${word}\\s*`, "i");
|
const externRegex = new RegExp(`^extern\\s+${word}\\s*`, "i");
|
||||||
const globalRegex = new RegExp(`^global\\s+${word}\\s*`, "i");
|
const globalRegex = new RegExp(`^global\\s+${word}\\s*`, "i");
|
||||||
const labelRegex = new RegExp(`^${word}:`, "i");
|
const labelRegex = new RegExp(`^${word}:`, "i");
|
||||||
|
|
@ -215,12 +177,14 @@ function searchForDefinition(lines, word, document) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined; // If no match is found
|
return undefined; // If no match is found
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in searchForDefinition:", error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deactivate() {
|
function deactivate() {
|
||||||
if (languageConfigDisposable) {
|
// No cleanup needed
|
||||||
languageConfigDisposable.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue