Skip to content

Commit

Permalink
Release ver. 0.2.0
Browse files Browse the repository at this point in the history
- add diagnostic
- add language services
- general optimization

See Changelog for details
  • Loading branch information
babyraging committed Apr 27, 2020
1 parent fc99f3a commit ca30774
Show file tree
Hide file tree
Showing 40 changed files with 2,551 additions and 733 deletions.
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vscode/
.gitignore/
.git/
**/*.ts
**/tsconfig.json
**/tslint.json
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@

## Release

## 0.2.0 27/04/2020
### Added
- Added lex/yacc parsers and language services
- Added feature: basic diagnostics support (lex/yacc)
- Added feature: rename symbol support (lex/yacc)
- Added feature: find references support (lex/yacc)

### Changed
- Architectural changing, now uses language service pattern
- Better completion handling/detection (lex/yacc)
- General optimization
- parsing time 3x less than before
- binary search to detect C code region, computation time reduced from O(n) to O(log(n))
- Updated README.md

### Bug Fixes
- Minor bug fixes related to completion handling/detection

## 0.1.2
### Added
- Added recognition of start condition block (lex)
Expand Down Expand Up @@ -43,7 +61,6 @@
- Fixed a bug on wrong detection of tokens (yacc)
- Fixed recognition of comment in %type, keywords, keywords-block, rules (yacc)


## 0.0.7
### Added
- Added comment highlight (lex)
Expand Down
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ This is yet an another syntax highlighter for lex/yacc and flex/bison.

This extension provides full syntax highlight for these languages and also for the embedded language C/C++.

This extension also supports some basic language features such as:
- Code diagnostic
- Auto-completion
- Hover feature
- Go to Definition
- Find references
- Rename Symbol

## Preview

### Completion for lex
![](images/lex_define.gif)

### Completion for yacc
![](images/yacc_symbol.gif)

### Diagnostic

![](images/redefinition.png)

### More examples

You can find more previews here [previews](images/README.md).

## Notice

Since 1.43.0 VSCode enabled a new feature called Semantic Highlighting, this extension supports it.

By default, only the built-in themes has semantic highlighting enabled, so if you are using a 3rd party theme for example [Dracula](https://github.com/dracula/visual-studio-code/) which doesn't support the semantic coloring yet, you have to add these lines to your `settings.json` file to have the feature enabled.
Expand All @@ -24,28 +50,9 @@ On left enabled, on right disabled

![](images/semantic_comparison.png)

### Completion features

### Auto-Completion for keywords, declared definitions in lex/flex

![](images/lex_define.gif)

![](images/lex_rule.gif)

### Auto-Completion for keywords, declared union types in yacc/bison

![](images/yacc_token.gif)


### Auto-Completion for symbols in yacc/bison
![](images/yacc_symbol.gif)

### Auto-Completion for symbol type in yacc/bison
![](images/yacc_type.gif)

## Requirements

VSCode 1.44.0+
VSCode ^1.44

## Contributors

Expand Down
24 changes: 24 additions & 0 deletions images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Feature examples
## Diagnostics

![](not_decl.png)
![](redefinition.png)

## Hover
![](hover.png)

## Auto-Completion for keywords, declared definitions in lex/flex

![](lex_define.gif)

![](lex_rule.gif)

## Auto-Completion for keywords, declared union types in yacc/bison

![](yacc_token.gif)

## Auto-Completion for symbols in yacc/bison
![](yacc_symbol.gif)

## Auto-Completion for symbol type in yacc/bison
![](yacc_type.gif)
Binary file added images/hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/missing_decl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/not_decl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/redefinition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "yash",
"displayName": "Yash",
"description": "Yet another syntax highlighter for lex/yacc & flex/bison.",
"version": "0.1.2",
"version": "0.2.0",
"engines": {
"vscode": "^1.44.0"
},
"license": "MIT",
"publisher": "daohong-emilio",
"icon": "assets/logo.png",
"repository": {
Expand Down
88 changes: 88 additions & 0 deletions src/documentCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*
* Modified to adapt the project
*--------------------------------------------------------------------------------------------*/

import { TextDocument } from 'vscode';

export interface DocumentCache<T> {
get(document: TextDocument): T;
onDocumentRemoved(document: TextDocument): void;
dispose(): void;
}

export function CreateDocumentCache<T>(maxEntries: number, cleanupIntervalTimeInSec: number, parse: (document: TextDocument) => T): DocumentCache<T> {
let languageModels: { [uri: string]: { version: number, languageId: string, cTime: number, languageModel: T } } = {};
let nModels = 0;

let cleanupInterval: NodeJS.Timer | undefined = undefined;
if (cleanupIntervalTimeInSec > 0) {
cleanupInterval = setInterval(() => {
const cutoffTime = Date.now() - cleanupIntervalTimeInSec * 1000;
const uris = Object.keys(languageModels);
for (const uri of uris) {
const languageModelInfo = languageModels[uri];
if (languageModelInfo.cTime < cutoffTime) {
delete languageModels[uri];
nModels--;
}
}
}, cleanupIntervalTimeInSec * 1000);
}

return {
get(document: TextDocument): T {
const version = document.version;
const languageId = document.languageId;
const languageModelInfo = languageModels[document.uri.toString()];
if (languageModelInfo && languageModelInfo.version === version && languageModelInfo.languageId === languageId) {
languageModelInfo.cTime = Date.now();
return languageModelInfo.languageModel;
}

const t0 = Date.now();
const languageModel = parse(document);
const t1 = Date.now();
console.log(`Parsing time ${t1 - t0}`);
languageModels[document.uri.toString()] = { languageModel, version, languageId, cTime: Date.now() };
if (!languageModelInfo) {
nModels++;
}

if (nModels === maxEntries) {
let oldestTime = Number.MAX_VALUE;
let oldestUri = null;
for (const uri in languageModels) {
const languageModelInfo = languageModels[uri];
if (languageModelInfo.cTime < oldestTime) {
oldestUri = uri;
oldestTime = languageModelInfo.cTime;
}
}
if (oldestUri) {
delete languageModels[oldestUri];
nModels--;
}
}
return languageModel;

},
onDocumentRemoved(document: TextDocument) {
const uri = document.uri.toString();
if (languageModels[uri]) {
delete languageModels[uri];
nModels--;
}
},
dispose() {
if (typeof cleanupInterval !== 'undefined') {
clearInterval(cleanupInterval);
cleanupInterval = undefined;
languageModels = {};
nModels = 0;
}
}
};
}
Loading

0 comments on commit ca30774

Please sign in to comment.