Skip to content

Commit

Permalink
Add XML documentation download and display, user comments to hover an…
Browse files Browse the repository at this point in the history
…d signature help (#34)

* add comments to hover

* wip on docs downloader

* change HoverBuilder result type

* wip

* can hover

* wip signature help docs

* add highlighting for escript inside markdown

* fixup downloading

* implement configuration updates

* finish up hover doc highlighting

* cleanup code symbols from comments

* Fix tests and various test implementations

* Create scripts dir for tests

* Remove multiline regex option

* fix string casting

* Use different std::filesystem::path ctor

* lalala windows lalala

* Run eslint

* Decouple DocsDownloader, LSPServer, LSPWorkspace; tests

* Address review comments
- Use raw strings in regex
- Incorrect usage of reference return for get_xml_doc_path

* add tests for xml + comment docs on hover

* add new line after codeblock end triple-backticks

* Skip duplicate configuration change events
  • Loading branch information
KevinEady committed Jan 10, 2024
1 parent 78e282d commit d69881d
Show file tree
Hide file tree
Showing 28 changed files with 1,583 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ coverage
.vscode-test
build
prebuilds
native/test/ecompile.cfg
native/test/scripts/ecompile.cfg
.vscode/c_cpp_properties.json
.vscode/settings.json
.cache
15 changes: 13 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ export function activate(context: ExtensionContext) {
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
const args = [`--storageUri=${context.storageUri}`];

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
run: { module: serverModule, transport: TransportKind.ipc, args },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
options: debugOptions,
args
}
};

Expand All @@ -44,6 +46,9 @@ export function activate(context: ExtensionContext) {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/*.{inc,em,src,cfg}')
},
initializationOptions: {
configuration: workspace.getConfiguration('escript')
}
};

// Create the language client and start the client.
Expand All @@ -58,6 +63,12 @@ export function activate(context: ExtensionContext) {
client.start();

activatePolDebug(context);

workspace.onDidChangeConfiguration(e => {
client.sendNotification('didChangeConfiguration', {
configuration: workspace.getConfiguration('escript')
});
});
}

export function deactivate(): Thenable<void> | undefined {
Expand Down
27 changes: 27 additions & 0 deletions grammars/codeblock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
fileTypes: []
injectionSelector: L:text.html.markdown
patterns:
- include: "#escriptdoc-code-block"
repository:
escriptdoc-code-block:
begin: "(^|\\G)(\\s*)(\\`{3,}|~{3,})\\s*(?i:(escriptdoc)(\\s+[^`~]*)?$)"
name: markup.fenced_code.block.markdown
end: "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$"
beginCaptures:
'3':
name: punctuation.definition.markdown
'4':
name: fenced_code.block.language.markdown
'5':
name: fenced_code.block.language.attributes.markdown
endCaptures:
'3':
name: punctuation.definition.markdown
patterns:
- begin: "(^|\\G)(\\s*)(.*)"
while: "(^|\\G)(?!\\s*([`~]{3,})\\s*$)"
contentName: meta.embedded.block.escriptdoc
patterns:
- include: source.escriptdoc
scopeName: markdown.escriptdoc.codeblock
91 changes: 91 additions & 0 deletions grammars/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
# `strings` and `numbers` shamelessly ripped from https://raw.githubusercontent.com/microsoft/vscode-textmate/main/test-cases/themes/syntaxes/c.json
scopeName: source.escriptdoc
name: EScript Markdown Documentation

patterns:
- include: '#symbolType'
- include: '#moduleUnit'
- include: '#functionDef'
- include: '#closeParen'
- include: '#variable'
- include: '#assignment'
- include: '#strings'
- include: '#numbers'

repository:
symbolType:
patterns:
- comment: Symbol type (module function, user function, variable, ...)
match: '^(\()([^)]+)(\))'
captures:
'1': { name: meta.parens.escriptdoc }
'2': { name: entity.name.type.escriptdoc }
'3': { name: meta.parens.escriptdoc }
functionDef:
patterns:
- comment: Functions (module, user)
match: '([a-zA-Z$_][0-9a-zA-Z$_]*)(\()'
captures:
'1': { name: entity.name.function.escriptdoc }
'2': { name: meta.function.definition.parameters.escriptdoc }
variable:
patterns:
- comment: Variables and parameters
match: '([a-zA-Z$_][0-9a-zA-Z$_]*)'
captures:
'1': { name: meta.definition.variable.name.escriptdoc }
assignment:
patterns:
- comment: Assignment
match: :=
captures:
'0': { name: keyword.operator.escriptdoc }
closeParen:
patterns:
- comment: Close parenthesis
match: '\)'
captures:
'0': { name: keyword.operator.escriptdoc }
strings:
patterns:
- begin: "\""
beginCaptures:
'0':
name: punctuation.definition.string.begin.escriptdoc
end: "\""
endCaptures:
'0':
name: punctuation.definition.string.end.escriptdoc
name: string.quoted.double.escriptdoc
patterns:
- include: "#string_escaped_char"
- begin: "'"
beginCaptures:
'0':
name: punctuation.definition.string.begin.escriptdoc
end: "'"
endCaptures:
'0':
name: punctuation.definition.string.end.escriptdoc
name: string.quoted.single.escriptdoc
patterns:
- include: "#string_escaped_char"
string_escaped_char:
patterns:
- match: |-
(?x)\\ (
\\ |
[abefnprtv'"?] |
[0-3]\d{,2} |
[4-7]\d? |
x[a-fA-F0-9]{,2} |
u[a-fA-F0-9]{,4} |
U[a-fA-F0-9]{,8} )
name: constant.character.escape.escriptdoc
- match: "\\\\."
name: invalid.illegal.unknown-escape.escriptdoc
numbers:
patterns:
- match: "\\b((0(x|X)[0-9a-fA-F]*)|(0(b|B)[01]*)|(([0-9]+\\.?[0-9]*)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
name: constant.numeric.escriptdoc
6 changes: 6 additions & 0 deletions native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ if (WIN32)
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/plib.lib"
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/clib.lib"
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/format.lib"
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/tinyxml.lib"
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/escriptgrammarlib.lib"
"${BSCRIPT_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}/stackwalk.lib"
"${BSCRIPT_SOURCE_DIR}/lib/antlr/install/lib/${ANTLR_LIB}"
Expand All @@ -92,6 +93,7 @@ else()
"${BSCRIPT_SOURCE_DIR}/bin/libplib.a"
"${BSCRIPT_SOURCE_DIR}/bin/libclib.a"
"${BSCRIPT_SOURCE_DIR}/bin/libformat.a"
"${BSCRIPT_SOURCE_DIR}/bin/libtinyxml.a"
"${BSCRIPT_SOURCE_DIR}/bin/libescriptgrammarlib.a"
"${BSCRIPT_SOURCE_DIR}/lib/antlr/install/lib/libantlr4-runtime.a"
)
Expand Down Expand Up @@ -157,4 +159,8 @@ if(MSVC)
)
endif()

target_compile_definitions(${PROJECT_NAME} PUBLIC
TIXML_USE_STL
)

add_definitions(-DNAPI_VERSION=5)
9 changes: 8 additions & 1 deletion native/cpp/binding.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <napi.h>

#include "napi/LSPWorkspace.h"
#include "napi/ExtensionConfig.h"
#include "napi/LSPDocument.h"
#include "napi/LSPWorkspace.h"

using namespace Pol::Bscript;

Expand All @@ -12,6 +13,12 @@ Napi::Object Init( Napi::Env env, Napi::Object exports )

exports.Set( Napi::String::New( env, "LSPDocument" ),
VSCodeEscript::LSPDocument::GetClass( env ) );

auto ExtensionConfiguration = Napi::Object::New( env );
ExtensionConfiguration["setFromObject"] =
Napi::Function::New( env, &VSCodeEscript::ExtensionConfiguration::SetFromObject );
exports.Set( Napi::String::New( env, "ExtensionConfiguration" ), ExtensionConfiguration );

return exports;
}

Expand Down
Loading

0 comments on commit d69881d

Please sign in to comment.