Skip to content

Commit

Permalink
Repair PUB/PRI docuentation parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Nov 17, 2023
1 parent f46deb6 commit afd6b4b
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 104 deletions.
6 changes: 6 additions & 0 deletions spin2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Possible next additions:
- Add new-file templates as Snippets
- Add additional Snippets as the community identifies them

## [2.2.5] 2023-11-17

Update for P1 and P2

- Fixed documentation parsing (Signature help, Hover text). Earlier changes broke this.

## [2.2.4] 2023-11-16

Update for P1 and P2
Expand Down
101 changes: 101 additions & 0 deletions spin2/TEST_LANG_SERVER/spin/comment_cert.spin
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
con { fixed io pins }

LIB_VERSION = 140 ' 1.4.0

SF_CS = 61 { O } ' flash chip select
SF_SCLK = 60 { O } ' flash clock
SF_MOSI = 59 { O } ' flash data in
SF_MISO = 58 { I } ' flash data out

' SK_* ENUM values (parameter to seek() method)
' SK_FILE_START: seek using position from start of file
' SK_CURRENT_POSN: seek where position is relative to current seek location in file
#0, SK_Unknown, SK_FILE_START, SK_CURRENT_POSN

E_BAD_HANDLE = -1 ' Error: Handle in invalid
E_NO_HANDLE = -2 ' Error: Out of available handles
E_FILE_NOT_FOUND = -3 ' Error: File not present

FIRST_BLOCK = $080 ' Physical address of first block in this flash file system
LAST_BLOCK = $FFF ' Physical address of last block in this flash file system
MAX_FILES_OPEN = 2 ' Maximum number of files that can be open at one time

BLOCKS = LAST_BLOCK - FIRST_BLOCK+1 ' Number of blocks in flash allocated to this file system
ID_TO_BLOCKS_SZ = (BLOCKS * 12 + 15) / 16 ' 12-bit fields in WORD array (rounded to full WORD)
FLAGS_SIZE = (BLOCKS * 1 + 7) / 8 ' 1-bit fields in BYTE array (rounded to full BYTE)
STATES_SIZE = (BLOCKS * 2 + 7) / 8 ' 2-bit fields in BYTE array (rounded to full BYTE)


B_FREE = %00 ' Block is not in use (free)
B_TEMP = %01 ' Block is being put to use
B_HEAD = %10 ' Block is head of a file (contains filename)
B_BODY = %11 ' BLock is body of file (any blocks after head)

dat { pre-initialized: driver state tracking tables }

' physically: 3/4 of a word (12 bits) for every valid block ID, 12 bits per ID
' logically: a "BLOCKS"-sized array of 12-bit variables, 1 for ea. block ID - indexed by block ID
' contains block_address in ea. 12 bit field
IDToBlocks WORD 0[ID_TO_BLOCKS_SZ] 'ID-to-block translation table
IDToBlock LONG 0 '(field pointer to 12-bit variables)

' physically: 1 byte for every 8 valid block IDs, 1 bit per block ID
' logically: a "BLOCKS"-sized array of single bit variables, 1 for ea. block ID - indexed by block ID
' contains [0,1] in ea. 1 bit field, where 1 means ID is valid
IDValids BYTE 0[FLAGS_SIZE] 'ID-valid flags
IDValid LONG 0 '(field pointer to 1-bit variables)

' physically: 1 byte for every 4 valid block IDs, 2 bits per block ID
' logically: a "BLOCKS"-sized array of 2-bit variables, 1 for ea. block ID - indexed by block ID
' contains a Block-State value in ea. 2 bit field [B_FREE, B_TEMP, B_HEAD, B_BODY]
BlockStates BYTE 0[STATES_SIZE] 'block states
BlockState LONG 0 '(field pointer to 2-bit variables)


hStatus BYTE 0[MAX_FILES_OPEN] 'handle: status [H_READ, H_WRITE, H_REPLACE]

pub null

'' This is not an application
'' (invoke format() or mount() to use the flash file system)


pub version : result

'' Returns flash file system library version as integer
'' -- e.g., version 120 is 1.2.0 (major, minor, bugfix)

return LIB_VERSION

pri get_file_head_signature(p_filename) : foundSignature | nameCrc, block_address, BYTE header[8 + FILENAME_SIZE]

' Look up file by name and return the block state bits of the files' head block (or 0 if file not found)
'
' @param p_filename - address of a zstring containing the filename
' @returns foundSignature - the block state bits of the head block (or 0 if file not found)

' Local Variables:
' @local block_address - the block offset within the file system
' @local BYTE header[FILENAME_SIZE] - a temp buffer the block's filename is read into for compare

nameCrc := calc_crc32(p_filename, strsize(p_filename)+1) 'get CRC of filename
repeat block_address from 0 to BLOCKS - 1 'scan head blocks for filename
flash_read_block(block_address, @nameCrc, $000, $007) 'yes, read first 4+4+128 bytes of block


pri calc_crc32(p_buffer, length) : crc
' Calculate and return the CRC for this buffer of length bytes
'
' @param p_buffer - the address of the buffer
' @returns crc - the calculated CRC for the buffer of length bytes

'return getcrc(p_buffer, $AD0424F3 rev 31, length) 'compute CRC of a buffered block

pri flash_read_block(block_address, p_buffer, firstByte, lastByte)

' Return byte(s) read from physical block into memory at p_buffer
'
' @param block_address - the block offset within the file system
' @param p_buffer - memory location in which to place the data
' @param firstByte - address of first byte to read
' @param lastByte - address of last byte to read
108 changes: 108 additions & 0 deletions spin2/TEST_LANG_SERVER/spin2/comment_cert.spin2
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
con { fixed io pins }

LIB_VERSION = 140 ' 1.4.0

SF_CS = 61 { O } ' flash chip select
SF_SCLK = 60 { O } ' flash clock
SF_MOSI = 59 { O } ' flash data in
SF_MISO = 58 { I } ' flash data out

' SK_* ENUM values (parameter to seek() method)
' SK_FILE_START: seek using position from start of file
' SK_CURRENT_POSN: seek where position is relative to current seek location in file
#0, SK_Unknown, SK_FILE_START, SK_CURRENT_POSN

E_BAD_HANDLE = -1 ' Error: Handle in invalid
E_NO_HANDLE = -2 ' Error: Out of available handles
E_FILE_NOT_FOUND = -3 ' Error: File not present

FIRST_BLOCK = $080 ' Physical address of first block in this flash file system
LAST_BLOCK = $FFF ' Physical address of last block in this flash file system
MAX_FILES_OPEN = 2 ' Maximum number of files that can be open at one time

BLOCKS = LAST_BLOCK - FIRST_BLOCK+1 ' Number of blocks in flash allocated to this file system
ID_TO_BLOCKS_SZ = (BLOCKS * 12 + 15) / 16 ' 12-bit fields in WORD array (rounded to full WORD)
FLAGS_SIZE = (BLOCKS * 1 + 7) / 8 ' 1-bit fields in BYTE array (rounded to full BYTE)
STATES_SIZE = (BLOCKS * 2 + 7) / 8 ' 2-bit fields in BYTE array (rounded to full BYTE)


B_FREE = %00 ' Block is not in use (free)
B_TEMP = %01 ' Block is being put to use
B_HEAD = %10 ' Block is head of a file (contains filename)
B_BODY = %11 ' BLock is body of file (any blocks after head)

dat { pre-initialized: driver state tracking tables }

' physically: 3/4 of a word (12 bits) for every valid block ID, 12 bits per ID
' logically: a "BLOCKS"-sized array of 12-bit variables, 1 for ea. block ID - indexed by block ID
' contains block_address in ea. 12 bit field
IDToBlocks WORD 0[ID_TO_BLOCKS_SZ] 'ID-to-block translation table
IDToBlock LONG 0 '(field pointer to 12-bit variables)

' physically: 1 byte for every 8 valid block IDs, 1 bit per block ID
' logically: a "BLOCKS"-sized array of single bit variables, 1 for ea. block ID - indexed by block ID
' contains [0,1] in ea. 1 bit field, where 1 means ID is valid
IDValids BYTE 0[FLAGS_SIZE] 'ID-valid flags
IDValid LONG 0 '(field pointer to 1-bit variables)

' physically: 1 byte for every 4 valid block IDs, 2 bits per block ID
' logically: a "BLOCKS"-sized array of 2-bit variables, 1 for ea. block ID - indexed by block ID
' contains a Block-State value in ea. 2 bit field [B_FREE, B_TEMP, B_HEAD, B_BODY]
BlockStates BYTE 0[STATES_SIZE] 'block states
BlockState LONG 0 '(field pointer to 2-bit variables)


hStatus BYTE 0[MAX_FILES_OPEN] 'handle: status [H_READ, H_WRITE, H_REPLACE]

pub null()

'' This is not an application
'' (invoke format() or mount() to use the flash file system)


pub version() : result

'' Returns flash file system library version as integer
'' -- e.g., version 120 is 1.2.0 (major, minor, bugfix)

return LIB_VERSION

pri get_file_head_signature(p_filename) : foundSignature | nameCrc, block_address, BYTE header[8 + FILENAME_SIZE]

' Look up file by name and return the block state bits of the files' head block (or 0 if file not found)
'
' @param p_filename - address of a zstring containing the filename
' @returns foundSignature - the block state bits of the head block (or 0 if file not found)

' Local Variables:
' @local block_address - the block offset within the file system
' @local BYTE header[FILENAME_SIZE] - a temp buffer the block's filename is read into for compare

nameCrc := calc_crc32(p_filename, strsize(p_filename)+1) 'get CRC of filename
repeat block_address from 0 to BLOCKS - 1 'scan head blocks for filename
if field[BlockState][block_address] == B_HEAD 'is this a head block?
flash_read_block(block_address, @header, $000, $007) 'yes, read first 4+4+128 bytes of block
'debug("* get header :", uhex_long(nameCrc,LONG[@header][1]))
if LONG[@header][1] == nameCrc 'does the filename match?
flash_read_block(block_address, @header + $008, $008, $088) 'yes, read first 4+4+128 bytes of block
if strcomp(p_filename, @header + $008) 'does the filename match?
foundSignature := LONG[@header] 'yes, return first long of header (always non-zero or logically TRUE)
quit ' end the repeat, we have our answer


pri calc_crc32(p_buffer, length) : crc
' Calculate and return the CRC for this buffer of length bytes
'
' @param p_buffer - the address of the buffer
' @returns crc - the calculated CRC for the buffer of length bytes

return getcrc(p_buffer, $AD0424F3 rev 31, length) 'compute CRC of a buffered block

pri flash_read_block(block_address, p_buffer, firstByte, lastByte)

' Return byte(s) read from physical block into memory at p_buffer
'
' @param block_address - the block offset within the file system
' @param p_buffer - memory location in which to place the data
' @param firstByte - address of first byte to read
' @param lastByte - address of last byte to read
2 changes: 1 addition & 1 deletion spin2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/Propeller.ico",
"author": "IronSheep",
"license": "MIT",
"version": "2.2.4",
"version": "2.2.5",
"repository": {
"type": "git",
"url": "https://github.com/ironsheep/P2-vscode-langserv-extension"
Expand Down
2 changes: 1 addition & 1 deletion spin2/scripts/LIVE-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/Propeller.ico",
"author": "IronSheep",
"license": "MIT",
"version": "2.2.4",
"version": "2.2.5",
"repository": {
"type": "git",
"url": "https://github.com/ironsheep/P2-vscode-langserv-extension"
Expand Down
2 changes: 1 addition & 1 deletion spin2/scripts/TEST-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "P1 and P2 Spin/Pasm Syntax/Semantic Highlighting w/Code Outline, Object Outline and Custom tabbing support",
"author": "IronSheep",
"license": "MIT",
"version": "2.2.4",
"version": "2.2.5",
"repository": {
"type": "git",
"url": "https://github.com/ironsheep/P2-vscode-langserv-extension"
Expand Down
31 changes: 20 additions & 11 deletions spin2/server/src/parser/spin.extension.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ export class ExtensionUtils {
};
}

public adjustWordPosition(document: TextDocument, position: lsp.Position, isInBlockComment: boolean, inPasmCodeStatus: boolean): [boolean, string, string, lsp.Position] {
const lineText = DocumentLineAt(document, position).trimEnd();
public adjustWordPosition(
document: TextDocument,
wordPosition: lsp.Position,
cursorPosition: lsp.Position,
isInBlockComment: boolean,
inPasmCodeStatus: boolean
): [boolean, string, string, lsp.Position] {
const lineText = DocumentLineAt(document, wordPosition).trimEnd();
const P2_LOCAL_LABEL_PREFIX: string = ".";
const P1_LOCAL_LABEL_PREFIX: string = ":";
const spin1File: boolean = isSpin1File(document.uri);
const localPasmLablePrefix: string = spin1File ? P1_LOCAL_LABEL_PREFIX : P2_LOCAL_LABEL_PREFIX;
const spinControlFlowKeywords: string[] = spin1File ? this.spin1ControlFlowKeywords : this.spin2ControlFlowKeywords;
let wordRange: lsp.Range | undefined = GetWordRangeAtPosition(lineText, position, spin1File);
let wordRange: lsp.Range | undefined = GetWordRangeAtPosition(lineText, wordPosition, spin1File);
if (inPasmCodeStatus) {
// do fixup for Spin2 pasm local labels
if (wordRange?.start.character > 0 && lineText.charAt(wordRange.start.character - 1) == localPasmLablePrefix) {
Expand All @@ -102,7 +108,7 @@ export class ExtensionUtils {
}
}
const tmpWord: string = wordRange ? document.getText(wordRange) : ""; // trim() shouldn't be needed!!!
this._logMessage(`+ sp2Utils: adjustWordPosition() orig tmpWord=[${tmpWord}](${tmpWord.length}), isInBlockComment=(${isInBlockComment})`);
this._logMessage(`+ sp2Utils: adjustWordPosition([${wordPosition.line},${wordPosition.character}]) orig tmpWord=[${tmpWord}](${tmpWord.length}), isInBlockComment=(${isInBlockComment})`);
let lineParts: string[] = [tmpWord];
let rangeDots: boolean = false;
if (!tmpWord.charAt(0).match(/[a-zA-Z_]/) && !tmpWord.startsWith(localPasmLablePrefix)) {
Expand Down Expand Up @@ -144,15 +150,18 @@ export class ExtensionUtils {
if (rangeDots) {
// use position to determine which word to return
const secondWordOffset: number = wordRange.start.character + lineParts[0].length + 2;
word = position.character >= secondWordOffset ? lineParts[1] : lineParts[0];
word = cursorPosition.character >= secondWordOffset ? lineParts[1] : lineParts[0];
} else {
// one dot or more ... we take only last two items, unless user wants just first word
word = lineParts[lineParts.length - 1];
objectRef = lineParts[lineParts.length - 2];
if (position.character < wordRange.start.character + lineParts[0].length) {
this._logMessage(`+ sp2Utils: adjustWordPosition() cursor=(${cursorPosition.character}), start=(${wordRange.start.character}), obj=[${objectRef}](${objectRef.length}), word=[${word}]`);
// if our cursor is in the object name part then return object name as our word
if (cursorPosition.character < wordRange.start.character + objectRef.length + 1) {
word = objectRef;
objectRef = "";
}
this._logMessage(`+ sp2Utils: adjustWordPosition() obj=[${objectRef}], word=[${word}]`);
}
break;
}
Expand All @@ -164,21 +173,21 @@ export class ExtensionUtils {
const stringsFound: IPairs[] = this.getStringPairOffsets(lineText);
const ticVarsFound: IPairs[] = this.getPairOffsetsOfTicVarWraps(lineText);
//const stringsFound: IPairs[] = [];
let bPositionInComment: boolean = this.isPositionInComment(lineText, position, stringsFound);
let bPositionInComment: boolean = this.isPositionInComment(lineText, wordPosition, stringsFound);
if (!bPositionInComment) {
bPositionInComment = isInBlockComment;
this._logMessage(`+ sp2Utils: adjustWordPosition() (post-block): bPositionInComment=${bPositionInComment}`);
}
if (!wordRange || this.isPositionInString(lineText, position, stringsFound, ticVarsFound) || bPositionInComment || word.match(/^\d+.?\d+$/) || spinControlFlowKeywords.indexOf(word) > 0) {
if (!wordRange || this.isPositionInString(lineText, wordPosition, stringsFound, ticVarsFound) || bPositionInComment || word.match(/^\d+.?\d+$/) || spinControlFlowKeywords.indexOf(word) > 0) {
this._logMessage(`+ sp2Utils: adjustWordPosition() EXIT false`);
return [false, null!, null!, null!];
}
if (PositionIsEqual(position, wordRange.end) && PositionIsAfter(position, wordRange.start)) {
position = PositionTranslate(position, 0, -1);
if (PositionIsEqual(wordPosition, wordRange.end) && PositionIsAfter(wordPosition, wordRange.start)) {
wordPosition = PositionTranslate(wordPosition, 0, -1);
}

this._logMessage(`+ sp2Utils: adjustWordPosition() EXIT true`);
return [true, objectRef, word, position];
return [true, objectRef, word, wordPosition];
}

public isPositionInString(lineText: string, position: lsp.Position, stringsInLine: IPairs[], ticVarsInLine: IPairs[]): boolean {
Expand Down
Loading

0 comments on commit afd6b4b

Please sign in to comment.