monaco-intellisense
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -17,7 +17,2 @@ import * as monaco from 'monaco-editor'; | ||
/** | ||
* Characters that trigger completion suggestions. | ||
* @default ['.'] | ||
*/ | ||
triggerCharacters?: string[]; | ||
/** | ||
* Delimiters used to trigger completion suggestions within template expressions. | ||
@@ -41,8 +36,23 @@ * @example | ||
/** | ||
* Represents the return type of the object module. | ||
*/ | ||
type ObjectReturn = { | ||
nested: (items: ObjectNestedCompletionItems, options: NestedOptions) => Disposable; | ||
/** | ||
* Registers a completion item provider for nested object properties. | ||
* | ||
* @param {ObjectNestedCompletionItems} items - The items to be used for completion suggestions. | ||
* @param {NestedOptions} options - Additional options for the completion provider. | ||
* @returns {Disposable} A disposable object that can be used to unregister the provider. | ||
*/ | ||
nested: (items: ObjectNestedCompletionItems, options?: NestedOptions) => Disposable; | ||
}; | ||
declare const object: (monaco: Monaco, language: string) => ObjectReturn; | ||
/** | ||
* Creates an object module that provides object intellisense methods. | ||
* @param {Monaco} monaco - The Monaco instance. | ||
* @param {string} [language] - The language to use for the object intellisense. Defaults to 'javascript'. | ||
*/ | ||
declare const object: (monaco: Monaco, language?: string) => ObjectReturn; | ||
export { object }; |
@@ -1,2 +0,3 @@ | ||
"use strict";var a=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},D=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of M(t))!R.call(e,n)&&n!==o&&a(e,n,{get:()=>t[n],enumerable:!(s=T(t,n))||s.enumerable});return e};var L=e=>D(a({},"__esModule",{value:!0}),e);var S={};P(S,{object:()=>K});module.exports=L(S);var b={triggerCharacters:["."],templateExpressionDelimiters:[],maxDepth:1/0,excludePrototype:!0};var f=e=>{let{model:t,position:o}=e;return t.getValueInRange({startLineNumber:o.lineNumber,startColumn:1,endLineNumber:o.lineNumber,endColumn:o.column})},_=e=>{let t=e.split(` | ||
`);return t[t.length-1].length+1},I=(e,t)=>({startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column-1+_(t)});var A=(e,t=!1,o)=>{switch(typeof e){case"object":return e===null?o.languages.CompletionItemKind.Value:o.languages.CompletionItemKind.Class;case"function":return t?o.languages.CompletionItemKind.Method:o.languages.CompletionItemKind.Function;default:return o.languages.CompletionItemKind.Variable}},x=(e,t)=>{let o=e.split(" ").pop()||"";if(t.some(n=>o.includes(n))){let n=-1,r=0;t.forEach(i=>{let m=o.lastIndexOf(i);m>n&&(n=m,r=i.length)}),n>=0&&(o=o.substring(n+r))}return o},O=(e,t)=>{if(!(t.charAt(t.length-1)==="."))return e;let s=t.slice(0,-1).split("."),n=e;for(let r of s)if(Object.prototype.hasOwnProperty.call(n,r))n=n[r];else return{};return n},N=(e,t,o,s)=>{let n="";try{n=t.__proto__.constructor.name}catch{n=typeof t}let r={label:e,kind:A(t,o,s.monaco),detail:n,insertText:e,insertTextRules:s.monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,range:I(s.position,e)};return n.toLowerCase()==="function"&&(r.insertText+="($0)",r.documentation=t.toString().split("{")[0]),r};var y=(e,t={})=>{let{maxDepth:o,excludePrototype:s,templateExpressionDelimiters:n}={...b,...t};return r=>{let i=f(r),m=x(i,n),h=O(e,m),j=m.charAt(m.length-1)===".",g=[];function d(p,C=0){if(!(C>=o)){for(let l in p)if(Object.prototype.hasOwnProperty.call(p,l)&&!l.startsWith("__")){let c=p[l];if(s&&!Object.prototype.hasOwnProperty.call(p,l))continue;g.push(N(l,c,j,r)),typeof c=="object"&&c!==null&&d(c,C+1)}}}return d(h),{suggestions:g}}};var u=(e,t)=>(o,s)=>{let n=y(o,s);return e.languages.registerCompletionItemProvider(t,{provideCompletionItems:(r,i)=>n({monaco:e,model:r,position:i})})};var K=(e,t)=>({nested:u(e,t)});0&&(module.exports={object}); | ||
"use strict";var c=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var o in e)c(t,o,{get:e[o],enumerable:!0})},y=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of M(e))!S.call(t,n)&&n!==o&&c(t,n,{get:()=>e[n],enumerable:!(r=D(e,n))||r.enumerable});return t};var A=t=>y(c({},"__esModule",{value:!0}),t);var U={};R(U,{object:()=>G});module.exports=A(U);var C=[".",'["',"['"],f="javascript",I={templateExpressionDelimiters:[],maxDepth:1/0,excludePrototype:!0};var x=t=>{let{model:e,position:o}=t;return e.getValueInRange({startLineNumber:o.lineNumber,startColumn:1,endLineNumber:o.lineNumber,endColumn:o.column})};var L=(t,e=!1,o)=>{switch(typeof t){case"object":return t===null?o.languages.CompletionItemKind.Value:o.languages.CompletionItemKind.Class;case"function":return e?o.languages.CompletionItemKind.Method:o.languages.CompletionItemKind.Function;default:return o.languages.CompletionItemKind.Variable}},b=(t,e)=>{let o=t.split(" ").pop()||"";if(e.some(n=>o.includes(n))){let n=-1,s=0;e.forEach(i=>{let l=o.lastIndexOf(i);l>n&&(n=l,s=i.length)}),n>=0&&(o=o.substring(n+s))}return o},O=(t,e,o)=>{if(!o)return t;let r=P(e),n=t[r[0]];if(r.length===0)return{};for(let s=1;s<r.length;s++)if(Object.hasOwn(n,r[s]))n=n[r[s]];else return{};return n},P=t=>{let e=(o,r,n)=>o.split(r).join(".").split(n).join(".").split(".").filter(Boolean);return t.includes("['")?e(t,"['","']"):t.includes('["')?e(t,'["','"]'):t.slice(0,-1).split(".").filter(Boolean)},N=t=>t.split(".").length,T=(t,e,o,r)=>{let{monaco:n}=r,s="";try{s=e.__proto__.constructor.name}catch{s=typeof e}let i={label:t,kind:L(e,o,n),detail:s,insertText:t,insertTextRules:n.languages.CompletionItemInsertTextRule.InsertAsSnippet};return s.toLowerCase()==="function"&&(i.insertText+=`($1) { | ||
$0 | ||
}`,i.documentation=e.toString().split("{")[0]),i};var E=(t,e={})=>{let{maxDepth:o,excludePrototype:r,templateExpressionDelimiters:n}={...I,...e};return s=>{let i=x(s),l=b(i,n),a=C.some(p=>l.includes(p)),g=O(t,l,a),h=N(l);if(Object.keys(g).length===0)return{suggestions:[]};let d=[];function j(p,_=0){if(!(_>o))for(let m in p)(r&&Object.hasOwn(p,m)||!r&&!m.startsWith("__"))&&d.push(T(m,p[m],a,s))}return j(g,h),{suggestions:d}}};var u=(t,e)=>(o,r)=>{let n=E(o,r);return t.languages.registerCompletionItemProvider(e,{triggerCharacters:[".",'"',"'"],provideCompletionItems:(s,i)=>n({monaco:t,model:s,position:i})})};var G=(t,e)=>({nested:u(t,e||f)});0&&(module.exports={object}); |
{ | ||
"name": "monaco-intellisense", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Your own Intellisense in Monaco Editor", | ||
@@ -15,2 +15,3 @@ "files": [ | ||
"test": "vitest --passWithNoTests", | ||
"dev:test": "pnpm -C test dev", | ||
"type-check": "tsc --noEmit", | ||
@@ -17,0 +18,0 @@ "lint": "eslint . --ext .ts,.tsx --fix", |
@@ -1,3 +0,77 @@ | ||
# Monaco IntelliSense | ||
# Monaco Intellisense | ||
Your own Intellisense in Monaco Editor. | ||
Monaco Intellisense is a library that provides custom IntelliSense (code completion) for the Monaco Editor, enabling rich code completion experiences within the Monaco Editor. | ||
## Installation | ||
```bash | ||
npm install monaco-intellisense | ||
``` | ||
## `object` | ||
The `object` module provides methods to register custom IntelliSense for objects within the Monaco Editor. | ||
### `object.nested` | ||
https://github.com/user-attachments/assets/a1e41f97-aacc-44bb-94a4-c17ed85ad062 | ||
The `object.nested` method registers a completion item provider for nested object properties. | ||
#### Parameters | ||
- `items` (ObjectNestedCompletionItems): The items to be used for completion suggestions. | ||
- `options` (NestedOptions, optional): Additional options for the completion provider. | ||
#### Example | ||
```typescript | ||
import * as monaco from 'monaco-editor'; | ||
import {object} from 'monaco-intellisense'; | ||
const editor = monaco.editor.create(document.getElementById('editor'), { | ||
value: '', | ||
language: 'javascript', | ||
}); | ||
const objectIntellisense = object(monaco).nested( | ||
{ | ||
user: { | ||
name: 'John Doe', | ||
age: 30, | ||
address: { | ||
street: '123 Main St', | ||
city: 'Anytown', | ||
zip: '12345', | ||
}, | ||
}, | ||
settings: { | ||
theme: 'dark', | ||
notifications: true, | ||
}, | ||
}, | ||
{ | ||
templateExpressionDelimiters: ['{{', '}}'], | ||
}, | ||
); | ||
editor.onDidDispose(() => { | ||
objectIntellisense.dispose(); | ||
}); | ||
``` | ||
### Options | ||
The `object.nested` method accepts an optional `options` parameter to configure the nested completion provider. The available options are: | ||
- `templateExpressionDelimiters` (string[]): Delimiters used to trigger completion suggestions within template expressions. | ||
- **Example**: `["{{", "}}"]` | ||
- This will allow to show completions even when the cursor is inside the {{}}. | ||
- `maxDepth` (number): Maximum depth to traverse when generating completion suggestions. | ||
- **Default**: `Infinity` | ||
- `excludePrototype` (boolean): Whether to exclude prototype properties from completion suggestions. | ||
- **Default**: `true` | ||
## License | ||
This project is licensed under the MIT License. See the [LICENSE](https://github.com/arshad-yaseen/monaco-intellisence/blob/main/LICENSE) file for details. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11069
73
78